SQL Cheat Sheet 2026

The 30 highest-yield SQL facts, distilled from real exam questions. Print it, save it as a PDF, or study it here — free, no sign-up.

78 questions
120 min time limit
63% to pass
  1. In SQL Server, how do you get the top 10 percent of rows? SELECT TOP 10 PERCENT
  2. Why might a DELETE fail due to a foreign key? Child rows still reference the row being deleted
  3. Why will the following SQL query fail? `SELECT ProductName FROM Products WHERE ProductID = (SELECT ProductID FROM OrderDetails WHERE Quantity > 100);` The subquery returns multiple rows, which cannot be compared using the `=` operator.
  4. To reuse a filtered subset of orders in two different joins within one query, a CTE helps by: Defining the subset once and referencing it by name
  5. What does CUME_DIST() compute? The cumulative distribution: fraction of rows at or below the current value
  6. Which SQL command is used to remove all rows but keep the table structure most efficiently? TRUNCATE
  7. A subquery that references a column from the outer query is called what? Correlated subquery
  8. What is a key benefit of using views to simplify complex joins? Users query one named object instead of rewriting the join
  9. How do ROWS and RANGE frame modes differ when there are duplicate ORDER BY values? ROWS counts physical rows; RANGE groups peers with equal values
  10. What is the difference between RANK() and DENSE_RANK() output for values 10,10,20? RANK gives 1,1,3 and DENSE_RANK gives 1,1,2
  11. Which of the SQL commands below deletes all rows in the SalesData table? DELETE FROM SalesData
  12. Which window function returns a value between 0 and 1 representing relative standing? PERCENT_RANK()
  13. Why might you use a window function instead of GROUP BY for aggregates? To keep individual rows while adding aggregate columns
  14. Which clause forces NULL values to appear first in PostgreSQL? ORDER BY col NULLS FIRST
  15. Which clause CANNOT typically contain a subquery in standard SQL? The keyword list of an INDEX definition
  16. Without an ORDER BY clause, the order of returned rows is: Not guaranteed
  17. What is a filtered index (also called a partial index)? An index built only on rows that satisfy a specified WHERE condition
  18. When using EXISTS, what should the subquery's SELECT list typically be? Irrelevant, often SELECT 1
  19. What does PERCENT_RANK() return for the very first row of an ordered partition? 0
  20. In ACID, what does Durability guarantee? Committed changes survive system failures
  21. Which returns rows less than AT LEAST ONE value from the subquery? < ANY
  22. Which gets a single random row efficiently in MySQL? ORDER BY RAND() LIMIT 1
  23. What is the result type of AVG over an integer column in most databases? A decimal or floating-point value
  24. A query needs to select all invoices with an `Amount` between 500 and 1000, inclusive of both values. Which `WHERE` clause correctly represents this condition? WHERE Amount BETWEEN 500 AND 1000
  25. Which clause defines a column that automatically gets a value when none is supplied on INSERT? DEFAULT
  26. Which command permanently saves a transaction's changes? COMMIT
  27. Which statement is used to remove a view from the database? DROP VIEW
  28. Why might WHERE bonus > 0 exclude rows where bonus is NULL? NULL comparisons yield unknown, not true
  29. To extract data from a database, which SQL statement is used? SELECT
  30. Which command adds a new column to an existing table? ALTER TABLE ... ADD COLUMN
Turn these facts into recall: