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
↧