File tree Expand file tree Collapse file tree 1 file changed +79
-0
lines changed Expand file tree Collapse file tree 1 file changed +79
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ Problem Descirption:
3+ +---------------+---------+
4+ | Column Name | Type |
5+ +---------------+---------+
6+ | id | int |
7+ | name | varchar |
8+ +---------------+---------+
9+ id is the primary key for this table.
10+ Each row of this table contains the id and the name of an employee in a company.
11+
12+
13+
14+ Table: EmployeeUNI
15+
16+ +---------------+---------+
17+ | Column Name | Type |
18+ +---------------+---------+
19+ | id | int |
20+ | unique_id | int |
21+ +---------------+---------+
22+ (id, unique_id) is the primary key for this table.
23+ Each row of this table contains the id and the corresponding unique id of an employee in the company.
24+
25+
26+
27+ Write an SQL query to show the unique ID of each user, If a user does not have a unique ID replace just show null.
28+
29+ Return the result table in any order.
30+
31+ The query result format is in the following example.
32+
33+
34+
35+ Example 1:
36+
37+ Input:
38+ Employees table:
39+ +----+----------+
40+ | id | name |
41+ +----+----------+
42+ | 1 | Alice |
43+ | 7 | Bob |
44+ | 11 | Meir |
45+ | 90 | Winston |
46+ | 3 | Jonathan |
47+ +----+----------+
48+ EmployeeUNI table:
49+ +----+-----------+
50+ | id | unique_id |
51+ +----+-----------+
52+ | 3 | 1 |
53+ | 11 | 2 |
54+ | 90 | 3 |
55+ +----+-----------+
56+ Output:
57+ +-----------+----------+
58+ | unique_id | name |
59+ +-----------+----------+
60+ | null | Alice |
61+ | null | Bob |
62+ | 2 | Meir |
63+ | 3 | Winston |
64+ | 1 | Jonathan |
65+ +-----------+----------+
66+ Explanation:
67+ Alice and Bob do not have a unique ID, We will show null instead.
68+ The unique ID of Meir is 2.
69+ The unique ID of Winston is 3.
70+ The unique ID of Jonathan is 1.
71+
72+ */
73+
74+ # Write your MySQL query statement below
75+
76+ SELECT unique_id, name
77+ FROM Employees
78+ LEFT JOIN EmployeeUNI
79+ USING (id)
You can’t perform that action at this time.
0 commit comments