Which of the following is using wrong syntax for a SELECT query in SQL?

2023

Which of the following is using wrong syntax for a SELECT query in SQL?

  1. A.

    SELECT WHERE RNO>100 FROM STUDENT; / SELECT WHERE RNO>100 FROM STUDENT;

  2. B.

    SELECT * FROM STUDENT WHERE RNO>100; / SELECT FROM STUDENT WHERE RNO>100;

  3. C.

    SELECT * FROM STUDENT WHERE RNO BETWEEN 100 AND 200; / SELECT FROM STUDENT WHERE RNO BETWEEN 100 AND 200;

  4. D.

    SELECT* FROM STUDENT WHERE RNO IN (100, 101, 105, 104); / SELECT FROM STUDENT WHERE RNO IN (100, 101, 105, 104);

Attempted by 845 students.

Show answer & explanation

Correct answer: A

Key rule: SQL SELECT syntax follows this order: SELECT <columns> FROM <table> WHERE <condition>.

  • Why the incorrect statement is wrong: SELECT WHERE RNO>100 FROM STUDENT; — This places the WHERE clause before the FROM clause and omits the column list. SQL requires the column list immediately after SELECT and the FROM clause before WHERE.

  • Corrected example for that case: SELECT * FROM STUDENT WHERE RNO > 100;

  • Why the other given statements are valid when columns are specified: use a column list or * after SELECT. Examples:

  • SELECT * FROM STUDENT WHERE RNO > 100;

  • SELECT * FROM STUDENT WHERE RNO BETWEEN 100 AND 200;

  • SELECT * FROM STUDENT WHERE RNO IN (100, 101, 105, 104);

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Niacl Ao It Specialist