TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst ยท 76.7K subscribers
Post #2227 3.75K
โœ… SQL JOINS ๐Ÿ”—๐Ÿ“˜

JOINS let you combine data from two or more tables based on related columns.

1๏ธโƒฃ INNER JOIN
Returns only matching rows from both tables.

Problem: Get customers with their orders.

SELECT c.name, o.order_id  
FROM customers c
INNER JOIN orders o ON c.id = o.customer_id;

โœ… Only shows customers who have orders.

2๏ธโƒฃ LEFT JOIN (or LEFT OUTER JOIN)
Returns all rows from the left table + matching rows from the right table. If no match, fills with NULL.

Problem: Show all customers, even if they didnโ€™t order.

SELECT c.name, o.order_id  
FROM customers c
LEFT JOIN orders o ON c.id = o.customer_id;

โœ… Includes customers without orders.

3๏ธโƒฃ RIGHT JOIN
Opposite of LEFT JOIN: keeps all rows from the right table.

4๏ธโƒฃ FULL OUTER JOIN
Returns all rows from both tables. Where thereโ€™s no match, it shows NULL.

SELECT c.name, o.order_id  
FROM customers c
FULL OUTER JOIN orders o ON c.id = o.customer_id;

โœ… Includes customers with or without orders and orders with or without customers.

5๏ธโƒฃ SELF JOIN
Table joins with itself.

Problem: Show employees and their managers.

SELECT e.name AS employee, m.name AS manager  
FROM employees e
JOIN employees m ON e.manager_id = m.id;

โœ… Links each employee to their manager using a self join.

๐Ÿ’ก Quick Summary:
โ€ข INNER JOIN โ†’ Only matches
โ€ข LEFT JOIN โ†’ All from left + matches
โ€ข RIGHT JOIN โ†’ All from right + matches
โ€ข FULL OUTER JOIN โ†’ Everything
โ€ข SELF JOIN โ†’ Table joins itself

๐Ÿ’ฌ Tap โค๏ธ for more!
  • โค 7
More from @sqlanalyst
  1. Oct 13, 2026SQL Interview Series โ€” Part 8 ๐Ÿ“Œ Question 8: Find Customers Who Have Never Placed an Orderโ€ฆ
  2. Oct 13, 2026๐—ง๐—ข๐—ฃ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐—ง๐—ข ๐—•๐—ข๐—ข๐—ฆ๐—ง ๐—ฌ๐—ข๐—จ๐—ฅ ๐—ฆ๐—ž๐—œ๐—Ÿ๐—Ÿ๐—ฆ ๐—œ๐—ก ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! Explorโ€ฆ
  3. Oct 12, 2026SQL Interview Series โ€” Part 6 ๐Ÿ“Œ Question 6: Find the Top 2 Highest-Paid Employees in Eachโ€ฆ
  4. Oct 12, 2026๐Ÿš€ ๐—ช๐—ต๐—ถ๐—ฐ๐—ต ๐—ง๐—ฒ๐—ฐ๐—ต ๐—ฆ๐—ธ๐—ถ๐—น๐—น ๐—ช๐—ถ๐—น๐—น ๐—ฌ๐—ผ๐˜‚ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ? Want to builโ€ฆ
  5. Oct 9, 2026SQL Interview Series โ€” Part 5 ๐Ÿ“Œ Question 5: Find Employees Who Earn More Than Their Managโ€ฆ
  6. Oct 9, 2026๐Ÿ‡ฎ๐Ÿ‡ณ ๐—š๐—ข๐—ฉ๐—˜๐—ฅ๐—ก๐— ๐—˜๐—ก๐—ง ๐—ข๐—™ ๐—œ๐—ก๐——๐—œ๐—” โ€” ๐—”๐—œ๐—–๐—ง๐—˜ ๐—œ๐—ก๐—ง๐—˜๐—ฅ๐—ก๐—ฆ๐—›๐—œ๐—ฃ๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ ๐Ÿš€โ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’