• Practice
  • About 14 min
  • 5 practice questions

SQL basics: SELECT, WHERE and common commands

Read simple SQL queries and predict their results, including SELECT, WHERE, ORDER BY and aggregate functions.

If something looks wrong, please tell us.

SQL (Structured Query Language) is the standard language for working with relational databases. Papers often show a small table and a query and ask for the result.

Basic statements

Common SQL
StatementPurpose
SELECTRetrieve data
INSERTAdd a new record
UPDATEChange existing data
DELETERemove records
CREATE TABLEMake a new table
WHEREFilter rows by a condition
ORDER BYSort the results

Example form: SELECT Name FROM Student WHERE Marks > 60; The query returns the names of students with marks above 60. Aggregate functions include COUNT, SUM, AVG, MAX and MIN.

Worked examples

Example 1. Student table: Asha 72, Bilal 55, Chitra 90, Dev 60. What does SELECT Name FROM Student WHERE Marks > 60 return? Marks above 60 are Asha (72) and Chitra (90). Dev's 60 is not greater than 60. Result: Asha, Chitra.

Example 2. For the same table, what does SELECT AVG(Marks) return? Sum = 72 + 55 + 90 + 60 = 277. Average = 277 / 4 = 69.25.

SELECT chooses columns, FROM names the table, WHERE filters rows, ORDER BY sorts.

— Rule to remember

Key takeaways: read a query from SELECT to WHERE, and check boundaries carefully: greater than excludes equal values.

Check your understanding

  1. 1. Student table marks: Asha 72, Bilal 55, Chitra 90, Dev 60. What does SELECT Name FROM Student WHERE Marks > 60; return?

    1. Asha, Chitra and Dev
    2. Bilal and Dev
    3. Asha and Chitra
    4. Chitra only
    Show answer

    Answer: C. Greater than 60 keeps 72 and 90. Dev's 60 is not greater than 60.

  2. 2. Student table marks: Asha 72, Bilal 55, Chitra 90, Dev 60. What does SELECT COUNT(*) FROM Student WHERE Marks >= 60; return?

    1. 2
    2. 4
    3. 1
    4. 3
    Show answer

    Answer: D. Greater than or equal to 60 keeps 72, 90 and 60: three rows.

  3. 3. Student table marks: Asha 72, Bilal 55, Chitra 90, Dev 60. What does SELECT AVG(Marks) FROM Student; return?

    1. 69.25
    2. 69
    3. 70
    4. 277
    Show answer

    Answer: A. Sum = 72 + 55 + 90 + 60 = 277; 277 / 4 = 69.25. (277 is the SUM.)

  4. 4. Which clause sorts the results of a query?

    1. WHERE
    2. ORDER BY
    3. FROM
    4. INSERT
    Show answer

    Answer: B. ORDER BY sorts; WHERE filters rows and FROM names the table.

  5. 5. Which statement makes a new table?

    1. INSERT
    2. UPDATE
    3. CREATE TABLE
    4. SELECT
    Show answer

    Answer: C. CREATE TABLE makes a table; INSERT adds a record to an existing one.

Privacy · Terms · Refunds · Delivery