开发者

SQL-Server/Access - Order BY 1,2?

I came across a query today,

SELECT col1,'yes' as col2  FROM myTable  
   WHERE col2=TR开发者_StackOverflow社区UE  
UNION  
SELECT col1,'no' as col2 FROM mytable  
   WHERE col2=FALSE  
ORDER BY 1,2  

I thought it would order by first column and then second but since a UNION is involved I am a bit unsure can someone explain the exact meaning of this query


SQL Server will union the results together (which is an implied select distinct) and then order the results by col1 then col2. In a union query, you can put an ORDER BY on the final select, which will sort the final result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜