Redian新闻
>
union function differenct between sql server 2005 and 2008?
avatar
i*7
2
有这样一个table A
ReportYear, ReportMonth, Reportdate, and others
以前用sql server 2005, 用以下query
Select year,month,date, other from A
Where criteria 1
Union
Select year,month,date, other from A
Where criteria 2
Query result自动按照年,月,日的顺序排列。
现在用sql server 2008,一样的query 得出的结果不是按照年,月,日由小到大的顺序
排列了。日期在后面可能排在前,这是为什么?
谢谢!
avatar
B*g
3
algorithm changed.
same thing happened for oracle 9i to oracle 10g.
If you need order, add order by

【在 i******7 的大作中提到】
: 有这样一个table A
: ReportYear, ReportMonth, Reportdate, and others
: 以前用sql server 2005, 用以下query
: Select year,month,date, other from A
: Where criteria 1
: Union
: Select year,month,date, other from A
: Where criteria 2
: Query result自动按照年,月,日的顺序排列。
: 现在用sql server 2008,一样的query 得出的结果不是按照年,月,日由小到大的顺序

avatar
i*a
4
Select year,month,date, other from A
Where criteria = 1
or criteria = 2
order by criteria, year, month, date

【在 i******7 的大作中提到】
: 有这样一个table A
: ReportYear, ReportMonth, Reportdate, and others
: 以前用sql server 2005, 用以下query
: Select year,month,date, other from A
: Where criteria 1
: Union
: Select year,month,date, other from A
: Where criteria 2
: Query result自动按照年,月,日的顺序排列。
: 现在用sql server 2008,一样的query 得出的结果不是按照年,月,日由小到大的顺序

avatar
i*a
5
is that the cause, or is it because the records' physical order changed
when migrating the database from 2005 to 2008?

【在 B*****g 的大作中提到】
: algorithm changed.
: same thing happened for oracle 9i to oracle 10g.
: If you need order, add order by

avatar
p*d
6
Is this the case, Beijing? Definitely if the physical order changed the
query result set order will change too if no ORDER BY clause specified.

【在 i****a 的大作中提到】
: is that the cause, or is it because the records' physical order changed
: when migrating the database from 2005 to 2008?

avatar
h*l
7
This one is NOT the same as the union query.
Union removes duplicates.

【在 i****a 的大作中提到】
: Select year,month,date, other from A
: Where criteria = 1
: or criteria = 2
: order by criteria, year, month, date

avatar
i*a
8
good catch
then:
Select year,month,date, other from A
Where criteria 1
Union
Select year,month,date, other from A
Where criteria 2
order by year, month, date

【在 h**l 的大作中提到】
: This one is NOT the same as the union query.
: Union removes duplicates.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。