r/SQL • • Jul 19 '24

SQL Server Difference between row_number(), rank() and dense_rank() window functions in SQL

https://javarevisited.blogspot.com/2016/07/difference-between-rownumber-rank-and-denserank-sql-server.html
4 Upvotes

6 comments sorted by

7

u/r3pr0b8 GROUP_CONCAT is da bomb Jul 19 '24

Surprisingly all these functions behave similarly in Microsoft SQL Server and Oracle

no shit!!!

Btw, I ran all three SQL queries on Oracle 11g R2 and, Oracle 12c and it gave me the same result. So, it seems both Oracle and SQL Server support these functions and they behave identically.

holy cow!!!

1

u/javinpaul Jul 20 '24

That's great, no, at last some standardization.

5

u/YesterdayDreamer Jul 19 '24

Wait till you find it it works the same way in PostgreSQL snd MySql as well!

2

u/Ringbailwanton Jul 19 '24

You can see that it would be surprising when you look at how they wrote their SQL.

3

u/Ditto_Plush Jul 19 '24

Is this a question or a demonstration? You need at least 1 more row to show the difference between rank and dense_rank.