题目
Table: Employees
1 | +---------------+---------+ |
Table: EmployeeUNI
1 | +---------------+---------+ |
Write an SQL query to show the unique ID of each user, If a user doesn’t have a unique ID replace just show null.
Return the result table in any order.
The query result format is in the following example:
Example 1:
1 | Employees table: |
解法
解法一:
左连接就会以左表Employee为准,将id相同的unique_id select 出来,如果在EmployeeUNI表中没有id对应的unique_id则返回null。
SQL
1 | select unique_id, name from Employees left join EmployeeUNI on Employees.id = EmployeeUNI.id |