Skip to content
Advertisement

Query to Id referencing to an ‘Id’ to the same table

I have a table AMZ_EMPLOYEE_DETAILS with Employee Id, Employee Name and Supervisor1 and Supervisor 2. The Supervisors are employee itself but represented by their name. My task was to replace the Supervisor names with their Ids.

enter image description here

I have used the following query to obtain the solution but it uses sub-queries and the query does look optimized. For this I have also made a dimension table with all the Id and Employee Names ,table AMZ_EMPLOYEE

The following is the expected output.

enter image description here

Advertisement

Answer

The logic to use two self-LEFT JOIN is correct. You don’t need to use subqueries though. Consider:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement