CBSE Class 12 · Computer Science (083)
CBSE Class 12 Computer Science SQL: SELECT with WHERE, BETWEEN, IN, LIKE, GROUP BY, HAVING, joins and aggregate functions — each query with the table it returns.
On these two tables (each result produced by running the query):
Table: EMPLOYEE
| EmpNo | Name | Gender | Salary | DeptNo | Bonus |
|---|---|---|---|---|---|
| 101 | Aarav | M | 52000 | 10 | 5000 |
| 102 | Diya | F | 61000 | 20 | NULL |
| 103 | Kabir | M | 45000 | 10 | 3000 |
| 104 | Meera | F | 70000 | 30 | 8000 |
| 105 | Rohan | M | 38000 | 20 | NULL |
| 106 | Sana | F | 58000 | 30 | 4000 |
| 107 | Vikram | M | 64000 | 10 | 6000 |
Table: DEPT
| DeptNo | DName | Location |
|---|---|---|
| 10 | Sales | Mumbai |
| 20 | Accounts | Delhi |
| 30 | Research | Pune |
| 40 | HR | Delhi |
Display all the records of the table EMPLOYEE.
SELECT * FROM EMPLOYEE;
| EmpNo | Name | Gender | Salary | DeptNo | Bonus |
|---|---|---|---|---|---|
| 101 | Aarav | M | 52000 | 10 | 5000 |
| 102 | Diya | F | 61000 | 20 | NULL |
| 103 | Kabir | M | 45000 | 10 | 3000 |
| 104 | Meera | F | 70000 | 30 | 8000 |
| 105 | Rohan | M | 38000 | 20 | NULL |
| 106 | Sana | F | 58000 | 30 | 4000 |
| 107 | Vikram | M | 64000 | 10 | 6000 |
Display the name and salary of employees earning more than 55000.
SELECT Name, Salary FROM EMPLOYEE WHERE Salary > 55000;
| Name | Salary |
|---|---|
| Diya | 61000 |
| Meera | 70000 |
| Sana | 58000 |
| Vikram | 64000 |
Display the different department numbers in EMPLOYEE (each only once).
SELECT DISTINCT DeptNo FROM EMPLOYEE ORDER BY DeptNo;
| DeptNo |
|---|
| 10 |
| 20 |
| 30 |
Display the details of employees whose salary is between 45000 and 60000 (both included).
SELECT * FROM EMPLOYEE WHERE Salary BETWEEN 45000 AND 60000 ORDER BY EmpNo;
| EmpNo | Name | Gender | Salary | DeptNo | Bonus |
|---|---|---|---|---|---|
| 101 | Aarav | M | 52000 | 10 | 5000 |
| 103 | Kabir | M | 45000 | 10 | 3000 |
| 106 | Sana | F | 58000 | 30 | 4000 |
Display the names of employees who work in department 10 or 30.
SELECT Name FROM EMPLOYEE WHERE DeptNo IN (10, 30) ORDER BY Name;
| Name |
|---|
| Aarav |
| Kabir |
| Meera |
| Sana |
| Vikram |
Display the names of employees whose name has 'a' as the second letter.
SELECT Name FROM EMPLOYEE WHERE Name LIKE '_a%' ORDER BY Name;
| Name |
|---|
| Aarav |
| Kabir |
| Sana |
Display the names of employees whose name ends with 'n'.
SELECT Name FROM EMPLOYEE WHERE Name LIKE '%n' ORDER BY Name;
| Name |
|---|
| Rohan |
Display the names of employees who have not been given a bonus.
SELECT Name FROM EMPLOYEE WHERE Bonus IS NULL ORDER BY Name;
| Name |
|---|
| Diya |
| Rohan |
PyRun is not affiliated with CBSE. Questions are written in the board's style for practice; they are not past papers.