CBSE Class 12 Computer Science Question 24 of 78

Simple Queries in SQL — Question 17

Back to all questions
17
Question

Question 17

Write SQL commands for the following on the basis of given table Teacher :

Table : Teacher

NoNameAgeDepartmentSalarySexDateofjoin
1Jugal34Computer12000M1997-01-10
2Sharmila31History20000F1998-03-24
3Sandeep32Maths30000M1996-12-12
4Sangeeta35History40000F1999-07-01
5Rakesh42Maths25000M1997-09-05
6Shyam50History30000M1998-06-27
7Shiv Om44Computer21000M1997-02-25
8Shalakha33Maths20000F1997-07-31
  1. To show all information about the teacher of history department.
  2. To list the names of female teachers who are in Hindi department.
  3. To list names of all teachers with their date of joining in ascending order.
Answer

1.

SELECT *
FROM Teacher
WHERE Department = 'History' ;
Output
+----+----------+-----+------------+--------+-----+------------+
| No | Name     | Age | Department | Salary | Sex | Dateofjoin |
+----+----------+-----+------------+--------+-----+------------+
|  2 | Sharmila |  31 | History    |  20000 | F   | 1998-03-24 |
|  4 | Sangeeta |  35 | History    |  40000 | F   | 1999-07-01 |
|  6 | Shyam    |  50 | History    |  30000 | M   | 1998-06-27 |
+----+----------+-----+------------+--------+-----+------------+

2.

SELECT Name
FROM Teacher
WHERE Sex = 'F' and Department = 'Hindi' ;
Explanation

There are no records in the Teacher table where the department is 'Hindi'. Hence, there will be no output.

3.

SELECT Name, Dateofjoin
FROM Teacher
ORDER BY Dateofjoin ;
Output
+----------+------------+
| Name     | Dateofjoin |
+----------+------------+
| Sandeep  | 1996-12-12 |
| Jugal    | 1997-01-10 |
| Shiv Om  | 1997-02-25 |
| Shalakha | 1997-07-31 |
| Rakesh   | 1997-09-05 |
| Sharmila | 1998-03-24 |
| Shyam    | 1998-06-27 |
| Sangeeta | 1999-07-01 |
+----------+------------+