Core SQL statement types (SELECT, INSERT, UPDATE, DELETE) and clause syntax explained with a short example query each.
42 cards · basic cards · AI-written, checked twice. Edit anything.
- What is the basic syntax for a SELECT statement?
Show answer
SELECT column1, column2 FROM table_name
- How do you filter rows in a SELECT with a WHERE clause?
Show answer
SELECT * FROM users WHERE age > 18
- What does the ORDER BY clause do?
Show answer
Sorts the result set by one or more columns: SELECT * FROM products ORDER BY price DESC
- What is the LIMIT clause used for?
Show answer
Restricts the number of rows returned: SELECT * FROM orders LIMIT 10
- What does DISTINCT do in a SELECT?
Show answer
Returns only unique values: SELECT DISTINCT country FROM customers
- How do you count rows with an aggregate function?
Show answer
SELECT COUNT(*) FROM employees
- What does the SUM aggregate function do?
Show answer
Adds up all values in a column: SELECT SUM(salary) FROM employees
- How do you find the average value in a column?
Show answer
SELECT AVG(price) FROM items
- What does the MAX function return?
Show answer
The highest value in a column: SELECT MAX(score) FROM games
- What does the MIN function return?
Show answer
The lowest value in a column: SELECT MIN(salary) FROM employees
- What is the GROUP BY clause used for?
Show answer
Groups rows by one or more columns: SELECT department, COUNT(*) FROM employees GROUP BY department
- How do you filter groups after GROUP BY?
Show answer
Use HAVING: SELECT department, COUNT(*) FROM employees GROUP BY department HAVING COUNT(*) > 5
- What is an INNER JOIN?
Show answer
Returns rows with matching values in both tables: SELECT * FROM orders INNER JOIN customers ON orders.customer_id = customers.id
- What is a LEFT JOIN?
Show answer
Returns all rows from left table and matching rows from right: SELECT * FROM customers LEFT JOIN orders ON customers.id = orders.customer_id
- What is a RIGHT JOIN?
Show answer
Returns all rows from right table and matching rows from left: SELECT * FROM orders RIGHT JOIN customers ON orders.customer_id = customers.id