CREATE TABLE books ( id INT PRIMARY KEY, title VARCHAR(200), author_id INT, FOREIGN KEY (author_id) REFERENCES authors(id) );
| Pitfall | Solution | |---------|----------| | from one-to-many joins | Use DISTINCT or understand your data model | | Slow performance | Ensure join columns are indexed | | Unexpected NULLs in outer joins | Use COALESCE(col, default_value) | | Accidental cross joins | Always specify an ON clause (or use USING ) | | Ambiguous column names | Prefix with table alias (e.g., e.id not just id ) | sql joins notes pdf
With these notes in hand (and saved to your hard drive), you will never confuse ON with WHERE again. CREATE TABLE books ( id INT PRIMARY KEY,
A column in one table that links to the primary key of another table. 2. Core Types of SQL Joins INNER JOIN Core Types of SQL Joins INNER JOIN SELECT A
SELECT A.name AS Employee, B.name AS Manager FROM employees A LEFT JOIN employees B ON A.manager_id = B.id;