Vous êtes sur la page 1sur 2

SQL Exam

Total Marks = 30
SECTION A – 2*4 = 8 marks
1. What is the difference between count(*) and count(id) ?

2. Write a query to select all the students from table ‘stud’ whose name begins with 'S'

3. Write a query to select all the records for which ‘gender’ is female or ‘age’ > 18 from the ‘emp’

4. Write a query to get the highest and lowest paid salary from each ‘dept’ from ‘emp’ table.

SECTION B – 3*5 = 15 marks

5. Write a query to fetch ‘empname’ from ‘employeedetails’ table and ‘salary’ from ‘employeesalary’
table; return employee details even if the salary is not present for the employee. (Link – empid in
both the tables)

6. Write a query to create a table named ‘persons’ with id, fname, lname, salary where salary should
accept values in the range 10000 to 90000 and set id as primary key.

7. Write a query to list the employee details (‘empid’, ‘empname’, ‘salary’) who has the same ‘salary’
from the employee table?

8. Write a query to find the number of products with a price more than or equal to Rs.350
(‘pro_price’) from the table item_mast.

9. Write a query to display the name of each company (com_name) from company_mast table; also
display price (pro_price) for their most expensive product along with prodcut Name (pro_name)
from item_mast table (Link – com_id in company_mast with pro_com in item_mast).

SECTION C – 1*7 = 7 marks

10. Create the table ‘employee’ with the below fields and make the id field as primary key

id name department manager salary

1 John IT 9 40000
2 Alex Corp 0 80000
3 Linda IT 9 35000
4 Rahul Purchase 8 30000
5 Ismail Purchase 8 44000
6 Zheng Sales 7 25000
7 Reiki Sales 2 60000
8 Aris Sales 2 59000
9 Jena IT 2 66000
10 Bonny IT 9 66000

Step 2 : Insert all the records as shown above and load the table employee like above

Step 3 : Write a query to list the employees who are not managers

Step 4 : Write a query to list the name of the managers who handle more than 2 reportees.

Step 5 : Write a query to fetch the employee whose salary is second lowest.

Step 6 : Write a query to fetch the records whose salary falls in the range 50000 and 80000