i******7 发帖数: 421 | 1 有这样一个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 得出的结果不是按照年,月,日由小到大的顺序
排列了。日期在后面可能排在前,这是为什么?
谢谢! | B*****g 发帖数: 34098 | 2 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 得出的结果不是按照年,月,日由小到大的顺序
| i****a 发帖数: 36252 | 3 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 得出的结果不是按照年,月,日由小到大的顺序
| i****a 发帖数: 36252 | 4 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
| p*********d 发帖数: 136 | 5 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?
| h**l 发帖数: 99 | 6 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
| i****a 发帖数: 36252 | 7 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.
|
|