SQL MCQ Questions and Answers: 40 Practice Questions with Explanations
By AbairTech Solution · Written by Oracle and database developers
Published by AbairTech Solution · Reviewed November 2026 · Editorial policy
How to use this page. Read the short study notes, then try each question before opening Show answer. Every answer has a one-line explanation, so you learn why the other options are wrong. The questions follow standard SQL; where Oracle behaves differently, the question says so.
SQL study notes before you start
SQL is the language every relational database speaks: Oracle, MySQL, PostgreSQL and SQL Server all use it with small differences. Most interview and exam questions test a handful of ideas, and if you understand these, the questions become much easier.
Logical order of a query. A query is written as SELECT … FROM … WHERE … GROUP BY … HAVING … ORDER BY, but the database processes it as FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY. This explains why you cannot use a column alias in WHERE, and why HAVING (not WHERE) filters aggregated groups.
NULL means unknown. Any comparison with NULL gives UNKNOWN, not TRUE or FALSE, so col = NULL never matches. Use IS NULL, and remember that aggregate functions such as SUM and COUNT(col) skip NULLs.
Joins. INNER JOIN keeps matching rows only; LEFT JOIN keeps every row from the left table; FULL OUTER JOIN keeps all rows from both; CROSS JOIN multiplies the row counts.
Questions 1–10: SELECT basics, filtering and NULLs
1. Which clause filters groups after GROUP BY has been applied?
WHERE
HAVING
ORDER BY
DISTINCT
Show answer
Answer: B – HAVING. WHERE filters individual rows before grouping; HAVING filters the groups afterwards, so it can use aggregates such as HAVING COUNT(*) > 5.
2. What does WHERE commission = NULL return?
All rows where commission is empty
All rows
No rows, because the comparison evaluates to UNKNOWN
A syntax error
Show answer
Answer: C. Comparing anything with NULL gives UNKNOWN, and WHERE only keeps TRUE rows. Write WHERE commission IS NULL instead.
3. A column has 10 rows, 3 of which are NULL. What does COUNT(column) return?
7
10
3
NULL
Show answer
Answer: A – 7. COUNT(column) ignores NULL values. COUNT(*) counts rows and would return 10.
4. Which LIKE wildcard matches exactly one character?
%
*
?
_ (underscore)
Show answer
Answer: D – underscore._ matches one character and % matches zero or more. * and ? are not SQL LIKE wildcards.
5.WHERE salary BETWEEN 1000 AND 2000 returns salaries that are:
Greater than 1000 and less than 2000
From 1000 to 2000, including both values
From 1000 up to but not including 2000
Outside the range 1000–2000
Show answer
Answer: B. BETWEEN is inclusive at both ends; it is shorthand for salary >= 1000 AND salary <= 2000.
6. Which keyword removes duplicate rows from a query result?
DISTINCT
SINGLE
ONLY
GROUP
Show answer
Answer: A – DISTINCT.SELECT DISTINCT city FROM customers returns each city once.
7. In logical processing order, which clause is evaluated first?
SELECT
WHERE
FROM
ORDER BY
Show answer
Answer: C – FROM. The database first identifies the source tables and joins, then applies WHERE, GROUP BY, HAVING, SELECT and finally ORDER BY.
8. Why does SELECT salary*12 AS annual FROM emp WHERE annual > 50000 fail?
Aliases cannot contain lowercase letters
Arithmetic is not allowed in SELECT
AS is not valid syntax
WHERE is processed before SELECT, so the alias does not exist yet
Show answer
Answer: D. Repeat the expression in WHERE (salary*12 > 50000) or use a subquery or CTE. Aliases can be used in ORDER BY, which runs after SELECT.
9. What is the default sort order of ORDER BY?
Descending
Ascending
Random
Insertion order
Show answer
Answer: B – ascending. Add DESC for descending. Without ORDER BY, the database guarantees no order at all.
10. What does COALESCE(NULL, NULL, 'Lahore', 'Karachi') return?
NULL
‘Karachi’
‘Lahore’
An error, because it has more than two arguments
Show answer
Answer: C – ‘Lahore’. COALESCE returns the first non-NULL argument and accepts any number of arguments. Oracle’s NVL accepts only two.
Questions 11–20: joins, subqueries and set operators
11. What does a LEFT JOIN return?
Only rows that match in both tables
All rows from the right table
Every combination of rows
All rows from the left table, with NULLs where no right-table row matches
Show answer
Answer: D. LEFT (OUTER) JOIN keeps every left-table row. It is the usual way to find “customers with no orders”: LEFT JOIN orders, then WHERE o.order_id IS NULL.
12. Table A has 5 rows and table B has 4 rows. How many rows does A CROSS JOIN B return?
9
20
5
4
Show answer
Answer: B – 20. A cross join returns the Cartesian product: every row of A paired with every row of B (5 × 4).
13. Which join returns all rows from both tables, matching where possible?
FULL OUTER JOIN
INNER JOIN
LEFT JOIN
NATURAL JOIN
Show answer
Answer: A. FULL OUTER JOIN combines the results of a left and a right join, filling NULLs on whichever side has no match.
14. A self join is:
A join without a condition
A join between a table and a view
A table joined to itself, using two aliases
A join that removes duplicates
Show answer
Answer: C. The classic example lists each employee with their manager: FROM emp e JOIN emp m ON e.manager_id = m.emp_id.
15. What is the difference between UNION and UNION ALL?
UNION ALL removes duplicates
UNION works only on numeric columns
There is no difference
UNION removes duplicates; UNION ALL keeps them and is usually faster
Show answer
Answer: D. UNION must sort or hash the result to remove duplicates. Use UNION ALL when duplicates are impossible or acceptable.
16.WHERE dept_id = (SELECT dept_id FROM depts WHERE city = 'Lahore') fails with “single-row subquery returns more than one row”. What is the fix?
Use IN instead of =
Add DISTINCT to the outer query
Use HAVING instead of WHERE
Add ORDER BY to the subquery
Show answer
Answer: A – use IN.= expects a single value. IN (or = ANY) accepts a list of values returned by the subquery.
17. What makes a subquery “correlated”?
It is placed in the FROM clause
It refers to a column from the outer query and is evaluated for each outer row
It returns exactly one row
It uses a GROUP BY
Show answer
Answer: B. Example: employees earning more than their department average – the subquery uses the outer row’s dept_id each time.
18.WHERE EXISTS (subquery) is TRUE when:
The subquery returns no rows
The subquery returns exactly one row
The subquery returns at least one row
The subquery returns no NULL values
Show answer
Answer: C. EXISTS only checks whether any row comes back; the selected columns do not matter, which is why SELECT 1 is common inside it.
19. Why can WHERE id NOT IN (SELECT manager_id FROM emp) return no rows at all?
NOT IN is not supported in subqueries
The subquery must use DISTINCT
NOT IN only works with numbers
If the subquery returns any NULL, every NOT IN comparison becomes UNKNOWN
Show answer
Answer: D. This is a common trap. Use NOT EXISTS, or add WHERE manager_id IS NOT NULL to the subquery.
20. Which keyword starts a Common Table Expression (CTE)?
WITH
DEFINE
TEMP
USING
Show answer
Answer: A – WITH.WITH dept_totals AS (SELECT …) SELECT … FROM dept_totals makes long queries easier to read, and recursive CTEs can walk hierarchies.
Questions 21–30: transactions, aggregates and window functions
21. Which command undoes changes that have not yet been committed?
REVOKE
ROLLBACK
UNDO
TRUNCATE
Show answer
Answer: B – ROLLBACK. ROLLBACK discards uncommitted DML. ROLLBACK TO savepoint_name undoes only the work after that savepoint.
22. Which statement removes all rows, keeps the table structure and, in Oracle, cannot be rolled back?
DELETE
DROP
TRUNCATE
MERGE
Show answer
Answer: C – TRUNCATE. TRUNCATE is DDL and commits implicitly. DELETE is DML (can be rolled back and can use WHERE); DROP removes the table itself.
23. In ACID, what does the “I” stand for?
Integrity
Indexing
Isolation
Insertion
Show answer
Answer: C – Isolation. Concurrent transactions should not see each other’s uncommitted work. The others are Atomicity, Consistency and Durability.
24. Which of these is NOT an aggregate function?
SUM
AVG
MAX
UPPER
Show answer
Answer: D – UPPER. UPPER is a single-row function that works on each value. Aggregates return one value for a group of rows.
25.SELECT dept_id, job, COUNT(*) FROM emp GROUP BY dept_id fails. Why?
job is not aggregated and not in GROUP BY
COUNT(*) cannot be used with GROUP BY
GROUP BY must come before FROM
dept_id must be aggregated
Show answer
Answer: A. Every non-aggregated column in SELECT must appear in GROUP BY. Add job to GROUP BY or wrap it in an aggregate.
26. What does ROW_NUMBER() OVER (PARTITION BY dept_id ORDER BY salary DESC) give?
The total salary of each department
A unique sequence number within each department, highest salary first
The same number for equal salaries
One row per department
Show answer
Answer: B. Filtering where this number = 1 is a common way to get the top earner per department without losing the other columns.
27. Scores are 95, 95 and 80. What does RANK() give the 80?
1
2
3
NULL
Show answer
Answer: C – 3. RANK leaves a gap after a tie (1, 1, 3). DENSE_RANK would give 2.
28. What does a window function do that GROUP BY does not?
It only works on numbers
It removes duplicate rows
It must be used in WHERE
It calculates across related rows while keeping every row in the result
Show answer
Answer: D. For example, SUM(amount) OVER (ORDER BY sale_date) gives a running total beside each sale row.
29. Which statement inserts new rows and updates existing ones in a single command?
UPSERT ALL
REPLACE
MERGE
ALTER
Show answer
Answer: C – MERGE.MERGE INTO target USING source ON (…) WHEN MATCHED THEN UPDATE … WHEN NOT MATCHED THEN INSERT … is standard SQL and widely used in Oracle data loads.
30. What is a deadlock?
A query that runs out of memory
Two sessions each waiting for a lock held by the other
A table with no primary key
A committed transaction that cannot be undone
Show answer
Answer: B. The database detects the cycle and rolls back one statement (in Oracle, ORA-00060). Locking rows in a consistent order helps prevent it.
Questions 31–40: keys, constraints, design and Oracle specifics
31. Which statement about a primary key is correct?
It must be unique and cannot be NULL
It allows one NULL value
A table can have several primary keys
It must be numeric
Show answer
Answer: A. A table has at most one primary key, which can span several columns (a composite key). Its values must be unique and not NULL.
32. What is the main purpose of a foreign key?
To speed up every query
To encrypt a column
To keep referential integrity between child and parent tables
To allow duplicate primary keys
Show answer
Answer: C. A foreign key stops you inserting an order for a customer that does not exist, or deleting a customer that still has orders (unless ON DELETE rules say otherwise).
33. Which constraint ensures that salary is always greater than zero?
UNIQUE
DEFAULT
NOT NULL
CHECK
Show answer
Answer: D – CHECK.CONSTRAINT chk_sal CHECK (salary > 0). Note that a CHECK condition that evaluates to UNKNOWN (a NULL salary) is allowed, so combine it with NOT NULL if needed.
34. What is a view?
A copy of a table’s data
A stored query that behaves like a virtual table
An index on several columns
A backup of the database
Show answer
Answer: B. A normal view stores no data; it runs its query when used. A materialized view stores the result and is refreshed.
35. What is the trade-off of adding an index?
Faster lookups, but slightly slower INSERT, UPDATE and DELETE and extra storage
Faster DML, but slower queries
Indexes remove the need for primary keys
There is no trade-off
Show answer
Answer: A. Every index must be maintained when data changes, so index the columns you actually filter and join on.
36. First Normal Form (1NF) requires that:
Every table has a foreign key
No column depends on another non-key column
Every column holds a single, atomic value, with no repeating groups
All columns are indexed
Show answer
Answer: C. Storing “Math, Physics” in one column breaks 1NF. Move multi-valued data into a separate child table.
37. Third Normal Form (3NF) removes:
Primary keys
All NULL values
Indexes
Transitive dependencies (non-key columns depending on other non-key columns)
Show answer
Answer: D. If an orders table stores customer_id and customer_city, the city depends on the customer, not the order, so it belongs in the customers table.
38. Which of these is a DCL (Data Control Language) command?
GRANT
COMMIT
CREATE
UPDATE
Show answer
Answer: A – GRANT. GRANT and REVOKE manage privileges. COMMIT is TCL, CREATE is DDL and UPDATE is DML.
39. In Oracle, what is the result of 'abc' || NULL?
NULL
‘abc’
An error
‘abcNULL’
Show answer
Answer: B – ‘abc’. Oracle treats NULL as an empty string in concatenation. Standard SQL (and PostgreSQL) would return NULL – a frequent difference in interviews.
40. Which clause returns only the first 10 rows in standard SQL (supported by Oracle 12c and later)?
LIMIT 10 ONLY
TOP 10
FETCH FIRST 10 ROWS ONLY
WHERE ROWS <= 10
Show answer
Answer: C.ORDER BY salary DESC FETCH FIRST 10 ROWS ONLY. MySQL and PostgreSQL also support LIMIT, and SQL Server uses TOP.
What to practise next
If you scored above 32 out of 40, you are ready for most SQL interview rounds. Below that, revisit NULL handling, joins and GROUP BY: they account for most wrong answers. Then move on to the PL/SQL MCQs to practise procedural code, or see all topics on the Programming MCQs hub. Oracle developers can continue with the 100 Oracle APEX MCQs.
Need an Oracle or SQL expert?
AbairTech builds and tunes Oracle databases, PL/SQL back ends and Oracle APEX applications for businesses.
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Strictly Necessary Cookies
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.