HomeSubjectsUniversityBlogAbout

SQL

Topic in Databases

210 total MCQsShowing 30 with explanations10 Easy10 Medium10 Hard

About This Topic

SQL (Structured Query Language) is the standard declarative language for defining, querying and modifying data in relational databases. Questions separate DDL commands such as CREATE, ALTER and DROP from DML commands like SELECT, INSERT, UPDATE and DELETE, and ask how a WHERE clause limits which rows change. You should know the logical order of SELECT clauses, GROUP BY with HAVING, aggregate functions and their NULL handling, LIKE wildcards, BETWEEN and IN, and the different JOIN types. Subqueries matter too: EXISTS versus IN, correlated subqueries that re-run for each outer row, and recursive common table expressions for hierarchical data.

Below are 30 practice questions from a pool of 210 SQL MCQs, one of 17 topics in Databases. Each shows the correct answer with an explanation; when you are ready, take a timed quiz to test recall under exam conditions.

Practice Questions

Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.

SQLEasy

Q1. SQL stands for:

  1. A.Standard Question Language
  2. B.Structured Query Language✓ Correct
  3. C.System Query Logic
  4. D.Simple Query Language

Explanation

SQL stands for Structured Query Language.

Report an error in this question

SQLEasy

Q2. Which SQL statement is used to retrieve data from a database?

  1. A.DELETE
  2. B.INSERT
  3. C.UPDATE
  4. D.SELECT✓ Correct

Explanation

The SELECT statement is used to retrieve data from one or more tables.

Report an error in this question

SQLEasy

Q3. Which SQL clause is used to filter rows?

  1. A.HAVING
  2. B.ORDER BY
  3. C.WHERE✓ Correct
  4. D.GROUP BY

Explanation

The WHERE clause filters rows based on specified conditions.

Report an error in this question

SQLEasy

Q4. Which SQL statement adds new rows to a table?

  1. A.UPDATE SET
  2. B.INSERT INTO✓ Correct
  3. C.ALTER TABLE
  4. D.CREATE INDEX

Explanation

INSERT INTO is used to add new rows to a table.

Report an error in this question

SQLEasy

Q5. Which SQL statement modifies existing data?

  1. A.DROP
  2. B.INSERT
  3. C.UPDATE✓ Correct
  4. D.SELECT

Explanation

The UPDATE statement modifies existing data in a table.

Report an error in this question

SQLEasy

Q6. Which SQL statement removes rows from a table?

  1. A.ALTER
  2. B.DELETE✓ Correct
  3. C.TRUNCATE
  4. D.DROP

Explanation

The DELETE statement removes rows from a table based on a condition.

Report an error in this question

SQLEasy

Q7. Which SQL command creates a new table?

  1. A.CREATE TABLE✓ Correct
  2. B.NEW TABLE
  3. C.INSERT TABLE
  4. D.ADD TABLE

Explanation

CREATE TABLE is used to create a new table in the database.

Report an error in this question

SQLEasy

Q8. Which SQL command permanently removes a table?

  1. A.DESTROY TABLE
  2. B.REMOVE TABLE
  3. C.DELETE TABLE
  4. D.DROP TABLE✓ Correct

Explanation

DROP TABLE permanently removes a table and all its data from the database.

Report an error in this question

SQLEasy

Q9. The ORDER BY clause is used to:

  1. A.Filter rows by value
  2. B.Join tables on keys
  3. C.Sort the result set✓ Correct
  4. D.Group rows together

Explanation

ORDER BY sorts the result set in ascending or descending order.

Report an error in this question

SQLEasy

Q10. Which keyword is used to remove duplicate rows from a result?

  1. A.FILTER
  2. B.UNIQUE
  3. C.REMOVE
  4. D.DISTINCT✓ Correct

Explanation

The DISTINCT keyword eliminates duplicate rows from the result set.

Report an error in this question

SQLMedium

Q11. Which SQL clause is used to filter groups in a GROUP BY query?

  1. A.WHERE
  2. B.HAVING✓ Correct
  3. C.ORDER BY
  4. D.LIMIT

Explanation

HAVING filters groups after GROUP BY, while WHERE filters individual rows before grouping.

Report an error in this question

SQLMedium

Q12. An INNER JOIN returns:

  1. A.All rows from the left table with NULLs for right
  2. B.Only rows that have matching values in both tables✓ Correct
  3. C.All rows from the right table with NULLs for left
  4. D.All rows from both the left and the right tables

Explanation

INNER JOIN returns only the rows where there is a match in both tables.

Report an error in this question

SQLMedium

Q13. Which aggregate function returns the number of rows?

  1. A.COUNT()✓ Correct
  2. B.SUM()
  3. C.AVG()
  4. D.MAX()

Explanation

COUNT() returns the number of rows that match a specified condition.

Report an error in this question

SQLMedium

Q14. A LEFT JOIN returns:

  1. A.The Cartesian product of both tables without any condition
  2. B.All rows from the right table and matching from the left
  3. C.Only rows that have matching values in both joined tables
  4. D.All rows from the left table and matching rows from the right✓ Correct

Explanation

LEFT JOIN returns all rows from the left table, with NULLs for non-matching right table columns.

Report an error in this question

SQLMedium

Q15. Which SQL constraint ensures a column cannot have NULL values?

  1. A.CHECK
  2. B.UNIQUE
  3. C.NOT NULL✓ Correct
  4. D.DEFAULT

Explanation

The NOT NULL constraint ensures that a column cannot have NULL values.

Report an error in this question

SQLMedium

Q16. The LIKE operator is used with which wildcard characters?

  1. A.# and @
  2. B.% and _✓ Correct
  3. C.* and ?
  4. D.& and ^

Explanation

The LIKE operator uses % (any sequence of characters) and _ (a single character) as wildcards.

Report an error in this question

SQLMedium

Q17. What does the IN operator do in SQL?

  1. A.Checks if a value matches any value in a list✓ Correct
  2. B.Performs an inner join between two given tables
  3. C.Inserts data into a specified target table row
  4. D.Indexes a column for faster search performance

Explanation

The IN operator checks whether a value matches any value in a specified list or subquery.

Report an error in this question

SQLMedium

Q18. Which SQL clause limits the number of rows returned?

  1. A.LIMIT (or TOP in SQL Server)✓ Correct
  2. B.GROUP BY (aggregation clause)
  3. C.HAVING (group filter clause)
  4. D.WHERE (filter condition clause)

Explanation

LIMIT (MySQL/PostgreSQL) or TOP (SQL Server) restricts the number of returned rows.

Report an error in this question

SQLMedium

Q19. A subquery is:

  1. A.A query that modifies existing data
  2. B.A query that creates new table objects
  3. C.A stored procedure in the database
  4. D.A query nested inside another query✓ Correct

Explanation

A subquery is a SELECT statement nested within another SQL statement.

Report an error in this question

SQLMedium

Q20. The BETWEEN operator selects values:

  1. A.Within a given inclusive range✓ Correct
  2. B.Outside a specified range only
  3. C.That are NULL valued entries
  4. D.Equal to a single specific value

Explanation

BETWEEN selects values within an inclusive range (including both endpoints).

Report an error in this question

SQLHard

Q21. A correlated subquery is different from a regular subquery because it:

  1. A.References columns from the outer query and executes once per outer row✓ Correct
  2. B.Does not reference the outer query and runs completely independently
  3. C.Is always faster than any other type of subquery in all situations
  4. D.Executes only once regardless of how many rows the outer query returns

Explanation

A correlated subquery references the outer query's columns and re-executes for each row of the outer query.

Report an error in this question

SQLHard

Q22. The COALESCE function in SQL:

  1. A.Calculates the average of numeric values
  2. B.Returns the last value in a specified list
  3. C.Concatenates strings from multiple columns
  4. D.Returns the first non-NULL value in a list✓ Correct

Explanation

COALESCE returns the first non-NULL expression in the list of arguments.

Report an error in this question

SQLHard

Q23. What is the difference between DELETE and TRUNCATE?

  1. A.TRUNCATE can have a WHERE clause to filter which specific rows should be removed from tables
  2. B.DELETE is faster than TRUNCATE because it removes all rows without any logging of the changes
  3. C.They are identical in function and there is no difference between them in any database system
  4. D.DELETE can have a WHERE clause and is logged; TRUNCATE removes all rows and is minimally logged✓ Correct

Explanation

DELETE is DML, can have WHERE, and logs each row deletion. TRUNCATE is DDL, removes all rows, and is minimally logged.

Report an error in this question

SQLHard

Q24. The CASE expression in SQL is used for:

  1. A.Managing concurrent transactions
  2. B.Dropping indexes from a table
  3. C.Creating tables in the database
  4. D.Conditional logic within a query✓ Correct

Explanation

The CASE expression provides if-then-else conditional logic within SQL queries.

Report an error in this question

SQLHard

Q25. A CROSS JOIN produces:

  1. A.An empty result set with no rows
  2. B.The intersection of two data tables
  3. C.Only rows matching between tables
  4. D.The Cartesian product of two tables✓ Correct

Explanation

A CROSS JOIN produces the Cartesian product — every row from the first table paired with every row from the second.

Report an error in this question

SQLHard

Q26. Which SQL statement is used to create an index?

  1. A.CREATE INDEX✓ Correct
  2. B.ADD INDEX
  3. C.INSERT INDEX
  4. D.MAKE INDEX

Explanation

CREATE INDEX is used to create an index on one or more columns of a table.

Report an error in this question

SQLHard

Q27. The EXISTS operator in SQL:

  1. A.Returns TRUE if the subquery returns at least one row✓ Correct
  2. B.Checks for NULL values in a specified column only
  3. C.Returns the count of rows matching in the subquery
  4. D.Creates a new table based on the subquery results

Explanation

EXISTS returns TRUE if the subquery returns one or more rows.

Report an error in this question

SQLHard

Q28. A self-join is:

  1. A.A cross join of two tables
  2. B.An outer join between tables
  3. C.A join of a table with itself✓ Correct
  4. D.A join without any conditions

Explanation

A self-join joins a table with itself, typically using aliases to distinguish the two instances.

Report an error in this question

SQLHard

Q29. UNION vs UNION ALL in SQL:

  1. A.They are identical in behavior and produce exactly the same result set
  2. B.UNION ALL removes duplicates while UNION keeps all including duplicates
  3. C.UNION removes duplicates; UNION ALL keeps all rows including duplicates✓ Correct
  4. D.UNION is faster because it skips the deduplication processing entirely

Explanation

UNION removes duplicate rows from the combined result, while UNION ALL includes all rows.

Report an error in this question

SQLHard

Q30. What does the NVL/IFNULL/ISNULL function do?

  1. A.Replaces NULL with a specified value✓ Correct
  2. B.Creates NULL constraints on columns
  3. C.Deletes all rows containing NULLs
  4. D.Counts NULL values in the column

Explanation

These functions replace NULL values with a specified default value (syntax varies by DBMS).

Report an error in this question

Ready to test yourself on SQL?

Take a timed quiz drawn from 210+ questions on this topic. No signup required — your progress saves in your browser.

Start SQL Quiz