T TestsWorld

Free practice test · Developer Skills

SQL Test (MySQL & PostgreSQL)

200 questions with a timer and instant results. Practise in short drills or take the full test, then see exactly which topics need work.

📝 200 questions ⏱ 150 min for all 🎯 Pass mark 60% 💸 Free, unlimited attempts 👥 29 people have taken it
⚡
Short drills

Pick 10, 25 or 50 questions for a quick round, or take all of them.

💡
Learn as you go

Practice mode shows the right answer and an explanation for every question.

📊
See your weak spots

Your result shows strong and weak topics and what to read next.

What's in the test

Easy 32% Medium 51% Hard 18%
COUNT With WHERE 1NULL Comparison 4IS NULL 2BETWEEN Operator 1LIKE Pattern Matching 2NOT IN With NULL 4IN With NULL 1COALESCE 2Operator Precedence 1COUNT Column Vs Star 1NULL Arithmetic 1WHERE Vs HAVING 1

Sample questions with answers

6 of the 200 questions in SQL Test (MySQL & PostgreSQL). Try each one, then open the answer.

  1. Question 1

    What does this query return?

    emp
    id | name | dept_id | salary | manager_id
    1 | Asha | 10 | 50000 | NULL
    2 | Ravi | 10 | 40000 | 1
    3 | Neha | 20 | 60000 | 1
    4 | Karan | 20 | 60000 | 3
    5 | Priya | NULL | 30000 | 3
    6 | Vikram | 30 | 45000 | 1
    
    SELECT COUNT(*) FROM emp WHERE dept_id = 10;
    • A. 2
    • B. 1
    • C. 3
    • D. 6
    Show answer
    Answer: A. 2
    Only Asha and Ravi have dept_id 10. WHERE keeps rows where the condition is true.
  2. Question 2

    What does this query return?

    emp
    id | name | dept_id | salary | manager_id
    1 | Asha | 10 | 50000 | NULL
    2 | Ravi | 10 | 40000 | 1
    3 | Neha | 20 | 60000 | 1
    4 | Karan | 20 | 60000 | 3
    5 | Priya | NULL | 30000 | 3
    6 | Vikram | 30 | 45000 | 1
    
    SELECT COUNT(*) FROM emp WHERE dept_id <> 10;
    • A. 4
    • B. 5
    • C. 6
    • D. 3
    Show answer
    Answer: D. 3
    Neha, Karan and Vikram qualify. Priya's dept_id is NULL, and NULL 10 is unknown, not true, so her row is dropped — a classic trap.
  3. Question 3

    What does this query return?

    emp
    id | name | dept_id | salary | manager_id
    1 | Asha | 10 | 50000 | NULL
    2 | Ravi | 10 | 40000 | 1
    3 | Neha | 20 | 60000 | 1
    4 | Karan | 20 | 60000 | 3
    5 | Priya | NULL | 30000 | 3
    6 | Vikram | 30 | 45000 | 1
    
    SELECT COUNT(*) FROM emp WHERE dept_id IS NULL;
    • A. 0
    • B. 6
    • C. 1
    • D. Error
    Show answer
    Answer: C. 1
    IS NULL is the correct way to test for missing values. Only Priya has no department.
  4. Question 4

    What does this query return?

    emp
    id | name | dept_id | salary | manager_id
    1 | Asha | 10 | 50000 | NULL
    2 | Ravi | 10 | 40000 | 1
    3 | Neha | 20 | 60000 | 1
    4 | Karan | 20 | 60000 | 3
    5 | Priya | NULL | 30000 | 3
    6 | Vikram | 30 | 45000 | 1
    
    SELECT COUNT(*) FROM emp WHERE dept_id = NULL;
    • A. 1
    • B. 0
    • C. 6
    • D. Error
    Show answer
    Answer: B. 0
    Any comparison with NULL using = gives unknown, so no row passes the filter. Use IS NULL instead; the query is legal, it just matches nothing.
  5. Question 5

    What does this query return?

    emp
    id | name | dept_id | salary | manager_id
    1 | Asha | 10 | 50000 | NULL
    2 | Ravi | 10 | 40000 | 1
    3 | Neha | 20 | 60000 | 1
    4 | Karan | 20 | 60000 | 3
    5 | Priya | NULL | 30000 | 3
    6 | Vikram | 30 | 45000 | 1
    
    SELECT name FROM emp WHERE salary BETWEEN 40000 AND 50000 ORDER BY name;
    • A. Vikram
    • B. Asha; Ravi; Vikram
    • C. Asha; Vikram
    • D. Asha; Ravi
    Show answer
    Answer: B. Asha; Ravi; Vikram
    BETWEEN is inclusive on both ends, so 40000 and 50000 both qualify. Vikram's 45000 is in the middle.
  6. Question 6

    What does this query return?

    emp
    id | name | dept_id | salary | manager_id
    1 | Asha | 10 | 50000 | NULL
    2 | Ravi | 10 | 40000 | 1
    3 | Neha | 20 | 60000 | 1
    4 | Karan | 20 | 60000 | 3
    5 | Priya | NULL | 30000 | 3
    6 | Vikram | 30 | 45000 | 1
    
    SELECT name FROM emp WHERE name LIKE '%a' ORDER BY name;
    • A. Asha; Neha; Priya
    • B. Asha
    • C. Asha; Karan; Neha; Priya
    • D. Asha; Karan; Neha; Priya; Ravi
    Show answer
    Answer: A. Asha; Neha; Priya
    '%a' means any characters followed by a final 'a'. Karan ends in 'n', so it does not match.

Want all 200 with a timer and a topic-wise result? Start the free test at the top of this page.

About this practice test

This SQL practice test covers the queries and concepts that come up most often in SQL rounds of hiring tests and technical interviews. Questions use standard SQL, with notes where MySQL or PostgreSQL behave differently.

What it covers

  • SELECT, WHERE, operators and NULL handling; ORDER BY, LIMIT and DISTINCT
  • Aggregates, GROUP BY and HAVING; inner, outer, self and cross joins
  • Subqueries, EXISTS and IN; UNION, INTERSECT and EXCEPT
  • Window functions (ROW_NUMBER, RANK, DENSE_RANK, LAG/LEAD, running totals) and CTEs, including recursive CTEs
  • DDL, constraints and keys; INSERT, UPDATE, DELETE and upserts
  • Indexes and EXPLAIN, transactions, ACID and isolation levels, normalization, views and triggers

Who it is for

Freshers and early-career developers and data analysts preparing for SQL rounds, online assessments and interviews.

Format

200 multiple-choice questions mixing query-output questions on small sample tables with concept questions. Each question shows a short explanation after you answer, including the common trap where there is one.

Free to attempt with a TestsWorld account. No card required.

Before you start: device, fullscreen and proctoring