August 22, 2012 at 2:38 pm
hi
can we user order by inside subquery?
August 22, 2012 at 2:44 pm
It's simple enough to test. Why don't you try it and report back the results?
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
August 23, 2012 at 12:20 am
You can use order by in sub query with TOP 100 PERCENT as sub query is treated as inline view
IE:
SELECT * FROM Tbale
WHERE ColumnName IN
(SELECT TOP 100 PERCENT ColumnName FROM Tbale ORDER BY ColumnName )
🙂
August 23, 2012 at 12:34 am
why not?
----------
Ashish
August 23, 2012 at 12:57 am
Try this one:
select * from Table1(nolock) T1 where T1.column1 in (select T2.column1 from Table2(nolock) T2 order by T2.column1 desc)
Regards,
Sumit Rastogi
August 23, 2012 at 1:18 am
harri.reddy (8/22/2012)
hican we user order by inside subquery?
Hi Harri,
As suggested by drew give it a try and you will come to know your own the result and the solution for that as well.:-)
--rhythmk
------------------------------------------------------------------
To post your question use below link
https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
🙂
August 23, 2012 at 1:37 am
Please also see many other posts for discussions on the dangers of nolock hints.
Mike
August 23, 2012 at 3:08 am
Sumit Rastogi (8/23/2012)
Try this one:select * from Table1(nolock) T1 where T1.column1 in (select T2.column1 from Table2(nolock) T2 order by T2.column1 desc)
Regards,
Sumit Rastogi
Hi Sumit,
It is the best practice to avoid nolock. It can provide you incorrect data.
--rhythmk
------------------------------------------------------------------
To post your question use below link
https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
🙂
August 23, 2012 at 4:38 am
You can with a TOP statement, but unless you have a row-limiting top SQL may very well just ignore the order by as there's no purpose for it.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply