Test Index
Structured Query Language (SQL)
© examsnet.com
Question : 55 of 58
Marks:
+1,
-0
Write the output of SQL queries (a) and (b) based on the following two tables DOCTOR and PATIENT belonging to the same database :Table : DOCTOR
Table : PATIENT
DNO | DNAME | FEES |
|---|---|---|
D1 | AMITABH | 1500 |
D2 | ANIKET | 1000 |
D3 | NIKHIL | 1500 |
D4 | ANJANA | 1500 |
PNO | PNAME | ADMDATE | DNO |
|---|---|---|---|
P1 | NOOR | 2021-12-25 | D1 |
P2 | ANNIE | 2021-11-20 | D2 |
P3 | PRAKASH | 2020-12-10 | NULL |
P4 | HARMEET | 2019-12-20 | D1 |
(a) SELECT DNAME, PNAME FROM DOCTOR NATURAL JOIN PATIENT ;(b) SELECT PNAME, ADMDATE, FEES FROM PATIENT P, DOCTOR D WHERE D.DNO = P.DNO AND FEES > 1000;
[CBSE 2022 Code 91]
Solution:
(a) NATURAL JOIN matches the rows on the common column DNO. Patient P3 (DNO NULL) and doctors D3, D4 (no patient) do not appear.
(The order of the rows may differ; the three pairs are the answer.)(b) Only doctor D1 (AMITABH) among the matched doctors has FEES > 1000 (ANIKET's fee is exactly 1000, so it is excluded):
| DNAME | PNAME |
| AMITABH | NOOR |
| AMITABH | HARMEET |
| ANIKET | ANNIE |
| PNAME | ADMDATE | FEES |
| NOOR | 2021-12-25 | 1500 |
| HARMEET | 2019-12-20 | 1500 |
© examsnet.com
Go to Question: