PostgreSQL SELF JOIN, CROSS JOIN, UNION and UNION ALL: Practical SQL Guide
These concepts are useful for SQL Developers, Data Analysts, and technical interviews. What You Will Learn What is a SELF JOIN? What is a CROSS JOIN? Difference between UNION and UNION ALL Practical SQL examples Common mistakes and interview questions 1. What Is a SELF JOIN? A SELF JOIN joins a table with itself. It is useful when records in the same table are related to each other. For example, an employee table may contain both employees and their managers. Create an Employee Table CREATE TABLE company_employees ( employee_id INT PRIMARY KEY, employee_name VARCHAR(50), manager_id INT ); INSERT INTO company_employees VALUES (1, 'Rahul', NULL), (2, 'Priya', 1), (3, 'Arjun', 1), (4, 'Sneha', 2), (5, 'Kiran', 2); Here, manager_id refers to another employee_id in the same table. Example: Display Employees and Their Managers SELECT e.employee_name AS employee, m.employee_name AS manager FROM company_employees e LEFT JOIN company...