Test Index
Structured Query Language (SQL)
© examsnet.com
Question : 51 of 58
Marks:
+1,
-0
(a) Consider the following tables – Student and Sport :Table : Student
Table : Sport
What will be the output of the following statement ? (1)
(i)
| ADMNO | NAME | CLASS |
|---|---|---|
| 1100 | MEENA | X |
| 1101 | VANI | XI |
| ADMNO | GAME |
|---|---|
| 1100 | CRICKET |
| 1103 | FOOTBALL |
SELECT * FROM Student, Sport;(b) Write the output of the queries (i) to (iv) based on the table, GARMENT given below : (2)TABLE : GARMENT
| GCODE | TYPE | PRICE | FCODE | ODR_DATE |
|---|---|---|---|---|
| G101 | EVENING GOWN | 850 | F03 | 2008-12-19 |
| G102 | SLACKS | 750 | F02 | 2020-10-20 |
| G103 | FROCK | 1000 | F01 | 2021-09-09 |
| G104 | TULIP SKIRT | 1550 | F01 | 2021-08-10 |
| G105 | BABY TOP | 1500 | F02 | 2020-03-31 |
| G106 | FORMAL PANT | 1250 | F01 | 2019-01-06 |
SELECT DISTINCT(COUNT(FCODE))FROM GARMENT;(ii) SELECT FCODE, COUNT(*), MIN(PRICE) FROM GARMENT GROUP BY FCODE HAVING COUNT(*)>1;(iii) SELECT TYPE FROM GARMENT WHERE ODR_DATE >'2021-02-01' AND PRICE <1500;(iv) SELECT * FROM GARMENT WHERE TYPE LIKE 'F%';[CBSE 2023 Compartment]
Solution:
(a)Two tables written after FROM without a join condition give their Cartesian product: every row of Student is joined with every row of Sport. Rows = 2 × 2 = 4, columns = 3 + 2 = 5.
(b)(i)
Key point: To count the different codes (3) the query must be
(iii) Orders after 2021-02-01 are G103 (2021-09-09, price 1000) and G104 (2021-08-10, price 1550); only G103 also has PRICE below 1500.
(iv)
| ADMNO | NAME | CLASS | ADMNO | GAME |
| 1100 | MEENA | X | 1100 | CRICKET |
| 1100 | MEENA | X | 1103 | FOOTBALL |
| 1101 | VANI | XI | 1100 | CRICKET |
| 1101 | VANI | XI | 1103 | FOOTBALL |
COUNT(FCODE) counts all non-NULL FCODE values in the table, i.e. all 6 rows (it does not count different codes). It gives one value, 6, and DISTINCT on that single row leaves it unchanged.| DISTINCT(COUNT(FCODE)) |
| 6 |
COUNT(DISTINCT FCODE); DISTINCT(COUNT(FCODE)) still gives 6.(ii) Groups: F01 = G103, G104, G106 (3 rows, lowest price 1000); F02 = G102, G105 (2 rows, lowest price 750); F03 = G101 (1 row, removed by HAVING COUNT(*) > 1).| FCODE | COUNT(*) | MIN(PRICE) |
| F02 | 2 | 750 |
| F01 | 3 | 1000 |
| TYPE |
| FROCK |
LIKE 'F%' selects types that begin with F.| GCODE | TYPE | PRICE | FCODE | ODR_DATE |
| G103 | FROCK | 1000 | F01 | 2021-09-09 |
| G106 | FORMAL PANT | 1250 | F01 | 2019-01-06 |
© examsnet.com
Go to Question: