Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Order by (select 0) meaning

$
0
0

Hi,

The thing I ask is probably very basic but I don't really get the point.

I found this query in one of the posts and I do not understand a part of it.

;WITH CTE AS
(
	SELECT	GroupID
	,		Name
	,		ROW_NUMBER() OVER(PARTITION BY GroupID ORDER BY (SELECT 0)) AS Ranking
	FROM	YourTable
)
SELECT	GroupID
,		Name
FROM	CTE
WHERE	Ranking = 1

I understand that ROW_NUMBER() requires an order by clause, but what order does 'order by (select 0)' generate? Why is it 0? Can it be any other constant?

Thanks.

P.



Viewing all articles
Browse latest Browse all 23857

Trending Articles



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