0

I am currently learning SQL, I was trying to get the 2nd highest salary using the following code:

SELECT Name, Address, Salary
FROM Employees 
ORDER BY Salary DESC
OFFSET 1 ROWS FETCH NEXT 1 ROWS ONLY;

This is the error that I am receiving: Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OFFSET 1 ROWS FETCH NEXT 1 ROWS ONLY' at line 4

I have read article online, but I still can't find what the error is.

1
  • This is sql-server code that youare attempting to use in MYSQL the 2 dialects are different. If you want to learn sql server there is a free version available Commented May 18, 2022 at 7:32

1 Answer 1

1

You have to use LIMIT instead of FETCH NEXT rows as it is not MySQL syntax. Also go through the following link where it is mentioned briefly SQL code error (OFFSET 0 ROWS FETCH FIRST 10 ROWS ONLY)

USE THE FOLLOWING QUERY INSTEAD OF ABOVE ONE TO GET SECOND HIGHEST VALUE

SELECT Name,Address,Salary from Employees GROUP BY Salary ORDER BY Salary DESC LIMIT 1,1
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I read some articles regarding this and all of them did the exact thing. I was so confused on what I am doing wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.