SQL
JOIN Queries
Multi-table join queries.
By EZ4Code Team
joinQuery
Code
-- INNER JOIN
SELECT u.name, o.order_date, o.total
FROM users u
INNER JOIN orders o ON u.id = o.user_id;
-- LEFT JOIN
SELECT u.name, o.order_date
FROM users u
LEFT JOIN orders o ON u.id = o.user_id;
-- Multi-table JOIN
SELECT u.name, p.title, oi.quantity
FROM users u
JOIN orders o ON u.id = o.user_id
JOIN order_items oi ON o.id = oi.order_id
JOIN products p ON oi.product_id = p.id;
-- Self join
SELECT e.name AS employee, m.name AS manager
FROM employees e
LEFT JOIN employees m ON e.manager_id = m.id;Explanation
JOIN combines data from multiple tables; INNER JOIN returns only matching rows, LEFT JOIN keeps all left table rows.
More SQL Snippets
SELECT with WHERE and ORDER BY
Filter, sort, and limit rows with SELECT, WHERE, and ORDER BY in SQL.
Subqueries
Nested queries.
Window Functions
Ranking and aggregate window functions.
Aggregate Functions
GROUP BY and HAVING.
CTE
Common Table Expressions.
Recursive Queries
Query hierarchical data with recursive CTE.