Skip to content
sqlbeginner

SQL Basics Quiz

SELECT, WHERE, ORDER BY, GROUP BY, JOINs, and fundamental SQL queries.

7 questions

By EZ4Code Team

1. Which SQL statement retrieves data from a table?

GET
SELECT
FETCH
RETRIEVE
Explanation: `SELECT` retrieves rows from one or more tables. Example: `SELECT name, age FROM users`. `GET` is HTTP, `FETCH` is a cursor operation in some databases, and `RETRIEVE` is not a SQL keyword.

2. Which clause filters rows in a SELECT?

SELECT * FROM users WHERE age > 18
WHERE
FILTER
IF
HAVING
Explanation: `WHERE` filters rows before grouping. `HAVING` filters after `GROUP BY` (on aggregated values). `FILTER` is not standard SQL (it exists as an alternative to CASE in some dialects). `IF` is a control-flow construct, not a row filter.

3. What does the `*` mean in `SELECT * FROM users`?

All rows where the value is *
All columns
Multiply the result
All primary keys
Explanation: `*` is a wildcard that means "all columns". It's convenient for exploration but discouraged in production code — explicitly listing columns is safer (schema changes won't break your app) and often faster.

4. Which JOIN returns only rows with matching values in both tables?

INNER JOIN
LEFT JOIN
RIGHT JOIN
FULL OUTER JOIN
Explanation: `INNER JOIN` returns only rows where there's a match in both tables. `LEFT JOIN` returns all left rows (with NULLs for non-matching right). `RIGHT JOIN` is the mirror. `FULL OUTER JOIN` returns all rows from both sides.

5. What does `ORDER BY` do?

SELECT * FROM products ORDER BY price DESC
Sorts the result set
Filters rows
Groups rows
Limits the result count
Explanation: `ORDER BY` sorts the result set by one or more columns. `ASC` (default) is ascending, `DESC` is descending. It's applied after WHERE and GROUP BY but before LIMIT.

6. What does `COUNT(*)` return?

SELECT COUNT(*) FROM orders WHERE status = 'shipped'
The number of rows matching the WHERE clause
The sum of all values
The first matching row
The number of columns
Explanation: `COUNT(*)` returns the number of rows in the group (including NULLs). `COUNT(column)` counts non-NULL values in that column. With a WHERE clause, it counts only matching rows.

7. Which keyword is used to insert new rows?

INSERT INTO users (name, email) VALUES ('Alice', '[email protected]')
INSERT INTO
ADD INTO
CREATE ROW
PUT INTO
Explanation: `INSERT INTO table (columns) VALUES (...)` adds new rows. You can insert multiple rows in one statement: `INSERT INTO users (name) VALUES ('A'), ('B')`. `ADD` is for ALTER TABLE (adding columns), not rows.

More sql Quizzes