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?
- SELECT column1, column2 FROM table_name
- How do you filter rows in a SELECT with a WHERE clause?
- SELECT * FROM users WHERE age > 18
- What does the ORDER BY clause do?
- Sorts the result set by one or more columns: SELECT * FROM products ORDER BY price DESC
- What is the LIMIT clause used for?
- Restricts the number of rows returned: SELECT * FROM orders LIMIT 10
- What does DISTINCT do in a SELECT?
- Returns only unique values: SELECT DISTINCT country FROM customers
- How do you count rows with an aggregate function?
- SELECT COUNT(*) FROM employees
- What does the SUM aggregate function do?
- Adds up all values in a column: SELECT SUM(salary) FROM employees
- How do you find the average value in a column?
- SELECT AVG(price) FROM items
- What does the MAX function return?
- The highest value in a column: SELECT MAX(score) FROM games
- What does the MIN function return?
- The lowest value in a column: SELECT MIN(salary) FROM employees
- What is the GROUP BY clause used for?
- Groups rows by one or more columns: SELECT department, COUNT(*) FROM employees GROUP BY department
- How do you filter groups after GROUP BY?
- Use HAVING: SELECT department, COUNT(*) FROM employees GROUP BY department HAVING COUNT(*) > 5
- What is an INNER JOIN?
- 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?
- 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?
- Returns all rows from right table and matching rows from left: SELECT * FROM orders RIGHT JOIN customers ON orders.customer_id = customers.id