Quantcast
Channel: Recent Edits
Viewing all articles
Browse latest Browse all 12198

The restriction on ORDER BY can be by-passed by putting the sub-query in a CTE

$
0
0
You can put the sub-query with an ORDER BY into a CTE and use that CTE in the main query.Example -use tempdbgocreate table a (col int)insert into a (col) values (1), (2), (3), (4), (5), (96), (97), (98), (99), (100)create table b (col int)insert into b (col) values (1), (98), (2), (99), (3), (100)select * from aselect * from b-- This gives errorselect col from aexceptselect top 3 b.col from b order by b.col desc/*Msg 4104, Level 16, State 1, Line 3The multi-part identifier "b.col" could not be b

Viewing all articles
Browse latest Browse all 12198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>