I have a table called Employee with the following fields:
I want to get top two employees with maximum salary. How do I write this query ?
SQL Server 2000+:
SELECT TOP 2
e.*
FROM EMPLOYEE e
ORDER BY e.salary DESC
MySQL & Postgres:
SELECT e.*
FROM EMPLOYEE e
ORDER BY e.salary DESC
LIMIT 2
Oracle:
SELECT x.*
FROM (SELECT e.*,
ROWNUM as rn
FROM EMPLOYEE e
ORDER BY e.salary DESC) x
WHERE x.rn <= 2
Try this ..
SELECT * from Employee order by Salary desc limit 2 ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With