JOIN’S admin, March 10, 2025March 10, 2025 1. INNER JOIN Returns records that have matching values in both tables. Only common data between both tables. Example: sqlCopyEditSELECT employees.name, employees.salary, department.dept_name FROM employees INNER JOIN department ON employees.dept_id = department.dept_id; Output: namesalarydept_nameJohn50000ITSarah60000HR 💡 2. LEFT JOIN (LEFT OUTER JOIN) Returns all records from the left table, and the matched records from the right table. If no match, NULL values will appear from the right table. Example: sqlCopyEditSELECT employees.name, employees.salary, department.dept_name FROM employees LEFT JOIN department ON employees.dept_id = department.dept_id; Output: namesalarydept_nameJohn50000ITSarah60000HRMike40000NULL 💡 3. RIGHT JOIN (RIGHT OUTER JOIN) Returns all records from the right table, and the matched records from the left table. If no match, NULL values will appear from the left table. Example: sqlCopyEditSELECT employees.name, employees.salary, department.dept_name FROM employees RIGHT JOIN department ON employees.dept_id = department.dept_id; Output: namesalarydept_nameJohn50000ITSarah60000HRNULLNULLSales 💡 4. FULL OUTER JOIN Returns all records when there is a match in either left table or right table. If no match, NULL values will appear. Example: sqlCopyEditSELECT employees.name, employees.salary, department.dept_name FROM employees FULL OUTER JOIN department ON employees.dept_id = department.dept_id; Output: namesalarydept_nameJohn50000ITSarah60000HRMike40000NULLNULLNULLSales 💡 5. CROSS JOIN Returns the Cartesian product of both tables. This means every row of the first table joins with every row of the second table. Example: sqlCopyEditSELECT employees.name, department.dept_name FROM employees CROSS JOIN department; Output: namedept_nameJohnITJohnHRSarahITSarahHR 💡 6. SELF JOIN Joins a table with itself. Useful for comparing values in the same table. Example: sqlCopyEditSELECT A.name AS Employee, B.name AS Manager FROM employees A, employees B WHERE A.manager_id = B.emp_id; Output: EmployeeManagerJohnSarahMikeJohn ✅ Summary JOIN TypeDescriptionINNER JOINReturns matching records from both tablesLEFT JOINReturns all records from the left table + matched from the right tableRIGHT JOINReturns all records from the right table + matched from the left tableFULL JOINReturns all records from both tablesCROSS JOINReturns cartesian product of both tablesSELF JOINJoins table with itself Spring Boot