Test Index

Structured Query Language (SQL) Get it on Google PlayDownload on the App Store CBSE Board Videos

© examsnet.com
Question : 37 of 58
Marks: +1, -0
Consider the tables Admin and Transport given below :
Table : Admin
S_idS_nameAddressS_type
S001SandhyaRohiniDay Boarder
S002VedanshiRohtakDay Scholar
S003VibhuRaj NagarNULL
S004AtharvaRampurDay Boarder
Table : Transport
S_idBus_noStop_name
S002TSS10Sarai Kale Khan
S004TSS12Sainik Vihar
S005TSS10Kamla Nagar
Write SQL queries for the following :
(i) Display the student name and their stop name from the tables Admin and Transport.
(ii) Display the number of students whose S_type is not known.
(iii) Display all details of the students whose name starts with 'V'.
(iv) Display student id and address in alphabetical order of student name, from the table Admin.
[CBSE 2024 Set 4]
Solution:  
(i)
SELECT S_name, Stop_name
FROM Admin, Transport
WHERE Admin.S_id = Transport.S_id;
(Equi-join on the common column S_id: gives Vedanshi with Sarai Kale Khan and Atharva with Sainik Vihar.)
(ii)
SELECT COUNT(*) FROM Admin
WHERE S_type IS NULL;
(A NULL value is tested with IS NULL, not with = NULL. Result: 1.)
(iii)
SELECT * FROM Admin
WHERE S_name LIKE 'V%';
(% matches any number of characters after V: Vedanshi and Vibhu.)
(iv)
SELECT S_id, Address FROM Admin
ORDER BY S_name;
(ORDER BY sorts in ascending (alphabetical) order by default.)
© examsnet.com
Advertisements
Go to Question: