Complete the code to select all records from the left table and matching records from the right table.
SELECT * FROM employees LEFT JOIN departments ON employees.department_id [1] departments.id;The LEFT JOIN requires an equality condition to match rows from the left and right tables.
Complete the code to count employees without a department.
SELECT COUNT(*) FROM employees LEFT JOIN departments ON employees.department_id = departments.id WHERE departments.id [1] NULL;To check for NULL values in SQL, use 'IS NULL' instead of '= NULL'.
Fix the error in the LEFT JOIN query to correctly show all customers and their orders.
SELECT customers.name, orders.id FROM customers [1] JOIN orders ON customers.id = orders.customer_id;LEFT JOIN returns all rows from the left table (customers) and matching rows from orders.
Fill both blanks to create a LEFT JOIN that shows all products and their sales, including products with no sales.
SELECT products.name, sales.amount FROM products [1] JOIN sales ON products.id [2] sales.product_id;
LEFT JOIN keeps all products, and '=' matches product IDs to sales.
Fill all three blanks to write a LEFT JOIN query that lists students with grades above 80.
SELECT students.name, grades.score FROM students [1] JOIN grades ON students.id [2] grades.student_id WHERE grades.score [3] 80;
LEFT JOIN, '=' matches IDs, and '> 80' filters grades above 80. Note the WHERE clause filters out non-matching rows.