<aside> 💡
This project generates a report that associates each employee's name with their unique ID if available. For employees without a unique ID, the result will display NULL. The solution demonstrates the use of SQL LEFT JOIN for combining data from multiple tables while retaining unmatched records.
</aside>
id in the Employees table.The task is to generate a table showing:
unique_id for employees if available, otherwise NULL.The query uses a LEFT JOIN to combine Employees with EmployeeUNI, ensuring all employees are included, even if they do not have a unique ID.
SELECT
EmployeeUNI.unique_id,
Employees.name
FROM
Employees
LEFT JOIN
EmployeeUNI
ON
Employees.id = EmployeeUNI.id;
LEFT JOIN EmployeeUNI ON Employees.id = EmployeeUNI.id links each employee in the Employees table with their unique ID in the EmployeeUNI table. Employees without a matching id in EmployeeUNI will have NULL in the unique_id column.EmployeeUNI.unique_id: Displays the unique ID or NULL if unavailable.Employees.name: Displays the name of the employee.