How do I resolve the SQL syntax error in my SELECT query?

clock-icon

asked 11 months ago

message-icon

1

eye-icon

85

I am running into a syntax error in my SQL query when trying to fetch records from the employees table. Here's my query:

1SELECT name, age, salary FROM employees WHERE department = 'Engineering' ORDER BY DESC salary;
1SELECT name, age, salary FROM employees WHERE department = 'Engineering' ORDER BY DESC salary;

1 Answer

Resolving SQL Syntax Error in SELECT Query

It looks like there is a syntax error in your SQL query. The issue lies in the ORDER BY clause. The correct syntax for ordering results should specify the column name first, followed by the ASC (ascending) or DESC (descending) keyword.

Here’s the corrected version of your query:

1SELECT name, age, salary FROM employees WHERE department = 'Engineering' ORDER BY salary DESC;
1SELECT name, age, salary FROM employees WHERE department = 'Engineering' ORDER BY salary DESC;

Key Changes Made:

  • ORDER BY Clause: The correct syntax is ORDER BY column_name [ASC|DESC]. In your case, it should be ORDER BY salary DESC;.

Additional Tips:

  • Always ensure that the column name in the ORDER BY clause is specified before the sorting direction.
  • If you encounter further syntax errors, double-check for missing commas, quotes, or incorrect keywords.

Feel free to reach out if you have more questions!

1

Write your answer here

Top Questions

    How do I resolve the SQL syntax error in my SELECT query?