Programming flashcards

SQL Basics: Queries & Joins

50 SQL flashcards for SELECT, joins, aggregation, CTEs, windows, transactions, constraints, and query plans.

50 cards By @mazo
#sql#queries#joins#database#interview
Study this deck free Browse Programming

About this deck

This 50-card SQL deck covers the path from SELECT and WHERE through joins, aggregation, subqueries, common table expressions, window functions, transactions, constraints, and EXPLAIN.

Notes identify NULL behavior, outer-join filter mistakes, and dialect differences that often trip up learners moving from toy queries to real databases.

50cards
SQL beginner to intermediatelevel
SQL beginners, analysts, backend developers, and interview learnersaudience

What you will learn

How to study this deck

Recommended study setup

Scope

The deck teaches portable SQL concepts with PostgreSQL-style examples. Exact syntax and behavior can differ across database systems.

Review notes

Query concepts checked against current PostgreSQL documentation and portable SQL behavior on 2026-07-10.

All 50 cards in this deck

FrontBackStudy note
SELECTChooses which columns to return from a table.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
FROMNames the table being queried.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
WHEREFilters rows by a condition.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
DISTINCTRemoves duplicate rows from the result.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
ORDER BYSorts the result set.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
LIMITRestricts the number of returned rows.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
INNER JOINReturns rows with matching values in both joined tables.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
LEFT JOINReturns all rows from the left table plus matching right-table rows.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
RIGHT JOINReturns all rows from the right table plus matching left-table rows.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
FULL OUTER JOINReturns matched rows plus unmatched rows from both tables.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
GROUP BYGroups rows so aggregate functions can summarize them.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
HAVINGFilters groups after aggregation (unlike WHERE, which filters rows).Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
COUNT(*)Counts rows in a group or table.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
SUM() / AVG()Add up or average the values in a column.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
INSERT INTOAdds new rows to a table.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
UPDATE ... SETChanges values in existing rows.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
DELETE FROMRemoves rows that match a condition.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
Primary keyA column or set of columns that uniquely identifies a row.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
Foreign keyA column that references the primary key of another table.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
INDEXA structure that speeds up lookups on one or more columns.Practice cue: write a small query against users and orders tables; exact syntax can vary slightly by database.
Column aliasRenames an output column with AS, such as total AS order_total.Aliases improve readability and can label computed expressions.
Table aliasGives a table a short name, such as FROM orders AS o.Qualify columns like o.id when multiple tables share names.
AND / ORCombine filter conditions.Use parentheses when mixing them so precedence is explicit.
IN (...)Tests whether a value matches any value in a list or subquery.Useful replacement for a chain of OR equality checks.
BETWEENTests an inclusive lower and upper bound.For timestamps, a half-open range is often safer than BETWEEN whole dates.
LIKEMatches text using % for many characters and _ for one character.Case sensitivity and alternatives such as ILIKE vary by database.
IS NULLTests for a missing SQL value.Do not use = NULL; comparisons with NULL produce unknown.
CASEReturns conditional values inside a query.Useful for labels, buckets, and conditional aggregates.
COALESCE()Returns the first non-NULL argument.Often used to provide a display or calculation fallback.
NULLIF(a, b)Returns NULL when a equals b; otherwise returns a.A common use is avoiding division by zero with NULLIF(denominator, 0).
MIN() / MAX()Return the smallest or largest non-NULL value.They work with dates and text as well as numbers.
SubqueryA query nested inside another SQL statement.It may return one value, one column, or a table-shaped result.
WITH ... AS (CTE)Names a query result for use by the following statement.CTEs can make multi-step logic easier to read.
UNIONCombines compatible result sets and removes duplicates.Column counts and compatible types must match.
UNION ALLCombines compatible result sets without removing duplicates.Usually faster when duplicate removal is unnecessary.
Window functionCalculates across related rows without collapsing them into one row per group.Uses an OVER clause.
ROW_NUMBER()Assigns a sequential number within a window ordering.Useful for ranking and selecting one row per group.
PARTITION BYDivides rows into groups for a window function.Unlike GROUP BY, it keeps individual rows in the result.
EXISTSReturns true when a subquery produces at least one row.Often expresses relationship checks clearly and can stop at the first match.
Correlated subqueryReferences columns from the outer query.It is logically evaluated per outer row, though the optimizer may transform it.
CROSS JOINReturns every combination of rows from both inputs.Row count multiplies, so use intentionally.
Self joinJoins a table to itself using different aliases.Useful for hierarchies, comparisons, and predecessor relationships.
Outer join filter pitfallA right-table condition in WHERE can remove NULL-extended rows from a LEFT JOIN.Put match conditions in ON when unmatched left rows must remain.
BEGIN / START TRANSACTIONStarts a transaction block.Exact syntax and automatic transaction behavior vary by database.
COMMIT / ROLLBACKCommit makes transaction changes permanent; rollback discards them.Use transactions for changes that must succeed or fail together.
UNIQUE constraintPrevents duplicate values in the constrained column set.NULL handling can differ by database.
NOT NULL constraintRequires a column to contain a value.Use when absence is invalid for the domain.
CHECK constraintRequires inserted or updated rows to satisfy a condition.It protects rules at the database boundary.
CREATE TABLEDefines a new table, its columns, types, and constraints.Choose constraints with the data model, not as an afterthought.
EXPLAINShows the database query plan.Use it to understand scans, joins, and index use before guessing at performance fixes.

Frequently asked questions

Does this SQL deck include joins?

Yes. It covers inner, left, right, full, cross, and self joins plus an outer-join filtering pitfall.

Does it cover advanced SQL?

It reaches CTEs, window functions, transactions, constraints, and EXPLAIN, but not database administration or deep performance tuning.

Will every query work in every database?

Core concepts are portable, but exact syntax and NULL, limit, or transaction behavior may vary by database.

Is the SQL Basics: Queries & Joins flashcard deck free?

Yes. You can study it free in your browser on MazoCards. Create a free account to save progress, track streaks, and sync across devices.

Git Commands Cheat Sheet

50 practical Git command flashcards for commits, branches, inspection, recovery, collaboration, and debugging history.

50 cards
Open

JavaScript Array Methods

50 JavaScript array method flashcards covering transformation, search, mutation, copying methods, iteration, and common pitfalls.

50 cards
Open

React Hooks Essentials

40 React 19.2 hook flashcards covering state, effects, refs, transitions, actions, external stores, common pitfalls, and when not to use a hook.

40 cards
Open

CSS Flexbox and Grid

CSS layout flashcards covering Flexbox, Grid, alignment, tracks, gaps, and responsive patterns.

41 cards
Open

Start studying SQL Basics: Queries & Joins

Study these 50 cards free, then create an account to save your progress and build a streak.