KnowledgeBoat Logo
|

Informatics Practices

In a Database Karnataka_Sangam there are two tables with the instances given below :

Table : STUDENTS

ADMNONAMECLASSSECRNADDRESSPHONE
1211Meena12D4A-263245678
1212Vani10D1B-255456789
1213Meena12A1
1214Karish10B3AB-2344567890
1215Suraj11C2ZW124345677

Table : SPORTS

ADMNOGAMECOACHNAMEGRADE
1215CricketMr. RaviA
1213VollyballMs. ChadhaB
1211VollyballMr. GovardhanA
1212Basket BallMr. TewaniB

Write SQL queries for the following :

(i) To count how many addresses are not having NULL values in the address column of STUDENTS table.

(ii) To display Name, Class from STUDENTS table and the corresponding Grade from SPORTS table.

(iii) To display Name of the student and their corresponding Coachnames from STUDENTS and SPORTS tables.

SQL Joins & Grouping

1 Like

Answer

(i)

SELECT COUNT(ADDRESS) FROM STUDENTS;
Output
+----------------+
| COUNT(ADDRESS) |
+----------------+
|              4 |
+----------------+

(ii)

SELECT S.NAME, S.CLASS, SP.GRADE 
FROM STUDENTS S, SPORTS SP 
WHERE S.ADMNO = SP.ADMNO;
Output
+-------+-------+-------+
| NAME  | CLASS | GRADE |
+-------+-------+-------+
| MEENA |    12 | A     |
| VANI  |    10 | B     |
| MEENA |    12 | B     |
| SURAJ |    11 | A     |
+-------+-------+-------+

(iii)

SELECT S.NAME, SP.COACHNAME 
FROM STUDENTS S, SPORTS SP 
WHERE S.ADMNO = SP.ADMNO;
Output
+-------+--------------+
| NAME  | COACHNAME    |
+-------+--------------+
| MEENA | MR.GOVARDHAN |
| VANI  | MR.TEWANI    |
| MEENA | MS.CHADHA    |
| SURAJ | MR.RAVI      |
+-------+--------------+

Answered By

1 Like


Related Questions