Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
laddu
Constraint Violating Yak Guru
332 Posts |
Posted - 2008-07-12 : 13:13:07
|
I would like to know the query to find the highest salary and top 3 salaries in employee tableThanks in advance |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
laddu
Constraint Violating Yak Guru
332 Posts |
Posted - 2008-07-12 : 14:33:46
|
Thank you Tkizer,How do we find only top 3 salary? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-12 : 14:41:41
|
quote: Originally posted by laddu Thank you Tkizer,How do we find only top 3 salary?
Use 2nd query provided by Tara.If you're using SQL 2005 you can even use ROW_NUMBER() function to get thisSELECT SalaryFROM(SELECT ROW_NUMBER() OVER(ORDER NY Salary DESC) AS RowNo,*FROM Employee)tWHERE t.RowNo=1 will give you highest salaryand SELECT SalaryFROM(SELECT ROW_NUMBER() OVER(ORDER NY Salary DESC) AS RowNo,*FROM Employee)tWHERE t.RowNo<=3 Will give you top 3 salaries. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-12 : 14:48:11
|
quote: Originally posted by tkizer What's the point of using the ROW_NUMBER() function though in a simple problem like this?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
I was just showing another way of doing it. |
|
|
|
|
|