Flashcards · SQL · Free
SQL flashcards, generated for you.
Example SQL study cards to learn from right now — then generate a full set from your own notes (plus a practice quiz) and export to Quizlet or Anki. Free, no account needed.
Example SQL flashcards
What does SQL stand for and what is its primary purpose?
SQL = Structured Query Language. It is used to query, insert, update, and delete data in relational databases.
What is the correct order of SQL clause execution?
FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT. SELECT is evaluated before ORDER BY, which is why you can't use column aliases in WHERE.
Why does SELECT * with a WHERE clause sometimes return unexpected results?
Common gotcha: NULL values don't match in comparisons. Use IS NULL or IS NOT NULL instead of = NULL or != NULL, since NULL compared to anything (including NULL) returns UNKNOWN, not TRUE.
What is the difference between INNER JOIN and LEFT JOIN?
INNER JOIN returns only rows with matches in both tables. LEFT JOIN returns all rows from the left table plus matching rows from the right table; unmatched right rows contain NULL.
Why might GROUP BY fail if you include non-aggregated columns without aggregation?
In standard SQL (MySQL strict mode, PostgreSQL), all non-aggregated columns in SELECT must appear in GROUP BY. Otherwise, the result is ambiguous—which row's value should be returned?
What is the difference between WHERE and HAVING?
WHERE filters rows before grouping; HAVING filters groups after aggregation. HAVING can reference aggregate functions; WHERE cannot.
Why does COUNT(*) behave differently from COUNT(column_name)?
COUNT(*) counts all rows including those with NULL values. COUNT(column_name) counts only non-NULL values in that column.
What is a gotcha with DISTINCT and multiple columns?
DISTINCT applies to the entire row combination, not individual columns. SELECT DISTINCT col1, col2 removes rows where both col1 AND col2 are identical; it doesn't deduplicate col1 independently.
How do UNION and UNION ALL differ, and when should you use each?
UNION removes duplicate rows and sorts results (slower); UNION ALL keeps all rows including duplicates (faster). Use UNION ALL unless you explicitly need deduplication.
Why can subqueries in SELECT fail, and what is the safe pattern?
A scalar subquery (in SELECT clause) must return exactly one row and one column. If it returns zero or multiple rows, it errors. Use LIMIT 1 or aggregate functions to ensure one value, or join instead for better performance.
Make your own SQL study set
Flashcards for related topics
Studying SQL to build with AI? MindloomHQ turns it into real skills — structured courses, agent projects, and certificates.
Explore MindloomHQ →