Introduction
Advanced joins help you combine data from multiple tables in smart ways to answer complex questions. They let you see relationships between data that simple queries can't show.
Jump into concepts and practice - no test required
SELECT columns FROM table1 JOIN_TYPE table2 ON join_condition;
SELECT * FROM customers INNER JOIN orders ON customers.id = orders.customer_id;
SELECT * FROM customers LEFT JOIN orders ON customers.id = orders.customer_id;
SELECT * FROM products LEFT JOIN sales ON products.id = sales.product_id WHERE sales.product_id IS NULL;
CREATE TABLE customers (id INT, name VARCHAR(20)); CREATE TABLE orders (id INT, customer_id INT, product VARCHAR(20)); INSERT INTO customers VALUES (1, 'Alice'), (2, 'Bob'), (3, 'Carol'); INSERT INTO orders VALUES (101, 1, 'Book'), (102, 1, 'Pen'), (103, 3, 'Notebook'); SELECT customers.name, orders.product FROM customers LEFT JOIN orders ON customers.id = orders.customer_id ORDER BY customers.id;
employees and departments on employees.dept_id = departments.id?LEFT JOIN table ON condition.orders and customers, what will the following query return?SELECT customers.name, orders.id FROM customers LEFT JOIN orders ON customers.id = orders.customer_id WHERE orders.id IS NULL;
SELECT a.id, b.value FROM tableA a RIGHT JOIN tableB b ON a.id = b.a_id WHERE a.id > 10;
students (id, name) and enrollments (student_id, course). You want to list all students and the courses they are enrolled in, including students with no enrollments. Which SQL query correctly achieves this?