Test Index
Structured Query Language (SQL)
© examsnet.com
Question : 37 of 58
Marks:
+1,
-0
Consider the tables
Table : Transport
Write SQL queries for the following :(i) Display the student name and their stop name from the tables
Admin and Transport given below :Table : AdminS_id | S_name | Address | S_type |
|---|---|---|---|
S001 | Sandhya | Rohini | Day Boarder |
S002 | Vedanshi | Rohtak | Day Scholar |
S003 | Vibhu | Raj Nagar | NULL |
S004 | Atharva | Rampur | Day Boarder |
S_id | Bus_no | Stop_name |
|---|---|---|
S002 | TSS10 | Sarai Kale Khan |
S004 | TSS12 | Sainik Vihar |
S005 | TSS10 | Kamla Nagar |
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_nameFROM Admin, TransportWHERE 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 AdminWHERE S_type IS NULL;(A NULL value is tested with
IS NULL, not with = NULL. Result: 1.)(iii)SELECT * FROM AdminWHERE S_name LIKE 'V%';(
% matches any number of characters after V: Vedanshi and Vibhu.)(iv)SELECT S_id, Address FROM AdminORDER BY S_name;(
ORDER BY sorts in ascending (alphabetical) order by default.)© examsnet.com
Go to Question: