-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsqlquery13.sql
61 lines (55 loc) · 3.64 KB
/
sqlquery13.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Problem Statement:
List out all the projects along with the employee's name and their respective allocated email ID.
Information about the table:
Table Employee:
+-------+-----------+----------+------+-------------------+-----------+-----------+
| EmpID | EmpFname | EmpLname | Age | EmailID | PhoneNo | City |
+-------+-----------+----------+------+-------------------+-----------+-----------+
| 1 | Riya | Khanna | 21 | riya@abc.com | 987655443 | Delhi |
| 2 | Sahil | Kumar | 32 | sahil@abc.com | 987657643 | Mumbai |
| 3 | Vishwas | Aanand | 24 | vishwas@abc.com | 987658871 | Kolkata |
| 4 | Harleen | Kaur | 27 | harleen@abc.com | 987677585 | Bengaluru |
| 5 | Priyanshu | Gupta | 23 | priyanshu@abc.com | 956758556 | Hyderabad |
+-------+-----------+----------+------+-------------------+-----------+-----------+
Table Project:
+-----------+-------+-------------+------------------+----------+
| ProjectID | EmpID | ProjectName | ProjectStartDate | ClientID |
+-----------+-------+-------------+------------------+----------+
| 100 | 1 | pro_1 | 2021-04-21 | 3 |
| 200 | 2 | pro_2 | 2021-03-12 | 1 |
| 300 | 3 | pro_3 | 2021-01-16 | 5 |
| 400 | 3 | pro_4 | 2021-04-27 | 2 |
| 500 | 5 | pro_5 | 2021-05-01 | 4 |
| 600 | 9 | pro_6 | 2021-01-19 | 1 |
| 700 | 7 | pro_7 | 2021-08-27 | 2 |
| 800 | 8 | pro_8 | 2021-09-15 | 3 |
+-----------+-------+-------------+------------------+----------+
Table Client_d:
+----------+-------------+-------------+------+-----------------+-----------+-----------+-------+
| ClientID | ClientFname | ClientLname | Age | ClientEmailID | PhoneNo | City | EmpID |
+----------+-------------+-------------+------+-----------------+-----------+-----------+-------+
| 1 | Steve | Rogers | 47 | steve@avg.com | 986674443 | Kolkata | 3 |
| 2 | Dustin | Poirier | 27 | dustin@ufc.com | 996767643 | Kolkata | 3 |
| 3 | Avinash | Jain | 24 | avinash@leg.com | 876588971 | Delhi | 1 |
| 4 | Sushant | Aggarwal | 23 | sushant@tek.com | 744355585 | Hyderabad | 5 |
| 5 | Param | Singh | 36 | param@xyz.com | 674445556 | Mumbai | 2 |
+----------+-------------+-------------+------+-----------------+-----------+-----------+-------+
Note-1: Write keywords of syntax in uppercase alphabets.
Note-2: Use employee ID to link the two tables.
Solution:
SELECT p.projectid, p.projectname, e.empfname, e.emplname, e.emailid FROM employee e
RIGHT JOIN project p
ON p.empid = e.empid;
Output:
+-----------+-------------+-----------+----------+-------------------+
| projectid | projectname | empfname | emplname | emailid |
+-----------+-------------+-----------+----------+-------------------+
| 100 | pro_1 | Riya | Khanna | riya@abc.com |
| 200 | pro_2 | Sahil | Kumar | sahil@abc.com |
| 300 | pro_3 | Vishwas | Aanand | vishwas@abc.com |
| 400 | pro_4 | Vishwas | Aanand | vishwas@abc.com |
| 500 | pro_5 | Priyanshu | Gupta | priyanshu@abc.com |
| 600 | pro_6 | NULL | NULL | NULL |
| 700 | pro_7 | NULL | NULL | NULL |
| 800 | pro_8 | NULL | NULL | NULL |
+-----------+-------------+-----------+----------+-------------------+