Post content
✅SQL Joins with Interview Q&A🔗💻 Joins combine data from multiple tables via common columns—essential for relational databases and analytics in 2025. 1️⃣ INNER JOIN Only matching records from both tables. SELECT e.name, d.department_name FROM employees e INNER JOIN departments d ON e.dept_id = d.id; Use: Employee names with their departments. 2️⃣ LEFT JOIN (LEFT OUTER JOIN) All left table rows + matching right; NULLs for no match. SELECT e.name, d.department_name FROM employees e LEFT JOIN departments d ON e.dept_id = d.id; Use: All employees, even without departments. 3️⃣ RIGHT JOIN (RIGHT OUTER JOIN) All right table rows + matching left. SELECT e.name, d.department_name FROM employees e RIGHT JOIN departments d ON e.dept_id = d.id; Use: All departments, even empty ones. 4️⃣ FULL OUTER JOIN All rows from both; NULLs where no match (PostgreSQL/MySQL supports). SELECT e.name, d.department_name FROM employees e FULL OUTER JOIN departments d ON e.dept_id = d.id; Use: Spot unmatched records. 5️⃣ SELF JOIN Table joins itself. SELECT a.name AS Employee, b.name AS Manager FROM employees a JOIN employees b ON a.manager_id = b.id; Use: Employee-manager hierarchy. Real-World Interview Questions + Answers Q1: What is the difference between INNER and OUTER JOIN? A: INNER returns only matches; OUTER includes unmatched from one/both tables. Q2: When would you use LEFT JOIN instead of INNER JOIN? A: To keep all left table rows, even without right matches. Q3: How can you find employees who don’t belong to any department? A: LEFT JOIN + IS NULL filter. SELECT e.name FROM employees e LEFT JOIN departments d ON e.dept_id = d.id WHERE d.department_name IS NULL; Q4: How would you find mismatched data between two tables? A: FULL OUTER JOIN + IS NULL on either side. Q5: Can you join more than two tables? A: Yes, chain JOINs: FROM A JOIN B ON... JOIN C ON... 💬Tap ❤️ for more!