SQL Practice Logo

SQLPractice Online

INNER JOIN Deep Dive: Functions

Module: Joins & Relationships

SELECT table1.column1, table2.column2 FROM table1 INNER JOIN table2 ON table1.foreign_key = table2.primary_key;

INNER JOIN returns only rows where join condition is TRUE in both tables

ON clause specifies the join condition - usually foreign_key = primary_key

Table aliases (FROM customers c) make queries shorter and more readable

Multiple conditions allowed with AND/OR in ON clause

WHERE clause filters results AFTER join executes

INNER keyword is optional - JOIN alone implies INNER JOIN

Non-matching rows are excluded from results (use LEFT JOIN to preserve them)

NULL foreign keys never match - excluded from INNER JOIN results

Standard INNER JOIN syntax. Excellent optimizer. EXPLAIN ANALYZE shows detailed execution.

Standard INNER JOIN syntax. Good optimizer. EXPLAIN shows execution plan.

Standard INNER JOIN syntax. Excellent optimizer. Execution Plan GUI available.

Standard INNER JOIN syntax. Mature optimizer. EXPLAIN PLAN shows execution.

Core references in this topic include WHERE, =, <, >, <=, >=. Learn what each one does, when to use it, and the execution or engine rules that matter.

WHERE

Filters rows before projection and sorting. It decides which rows continue through the query pipeline.

SELECT ... FROM table WHERE condition;

Most performance issues start with a weak WHERE clause or a missing supporting index.

=

Returns rows where the left and right values are exactly equal.

column = value

Use with exact matches. Do not use = NULL.

<, >, <=, >=

Range comparison operators for less-than, greater-than, and inclusive boundary checks.

salary >= 80000

BETWEEN

Checks whether a value falls inside an inclusive lower/upper range.

order_total BETWEEN 100 AND 500

LIKE

Pattern-matching operator for wildcard string searches.

name LIKE 'Joh%'

ANY / ALL

Compares one value against every or at least one value from a subquery result.

salary > ALL (SELECT salary FROM interns)

INTERVAL

Represents a duration that can be added to or subtracted from dates and timestamps.

order_date + INTERVAL '7 days'

PRIMARY KEY

Uniquely identifies each row and implicitly requires NOT NULL.

customer_id INT PRIMARY KEY