SQL
Question 1 |
Consider a relational database containing the following schemas.

The primary key of each table is indicated by underlying the constituent fields.
SELECT s.sno, s.sname
FROM Suppliers s, Catalogue c
WHERE s.sno = c.sno AND
Cost > (SELECT AVG (cost)
FROM Catalogue
WHERE pno = ‘P4’
GROUP BY pno);
The number of rows returned by the above SQL query is
0 | |
5 | |
4 | |
2 |
AVG(COST)
------------
225
The outer query “select s.sno,s.sname from suppliers s, catalogue c where s.sno=c.sno” returns:
SNO SNAME
----------------------------------------
S1 M/s Royal furniture
S1 M/s Royal furniture
S1 M/s Royal furniture
S2 M/s Balaji furniture
S2 M/s Balaji furniture
S3 M/s Premium furniture
S3 M/s Premium furniture
S3 M/s Premium furniture
S3 M/s Premium furniture
So, the final result of the query is:
SN SNAME
----------------------------------------
S2 M/s Balaji furniture
S3 M/s Premium furniture
S3 M/s Premium furniture
S3 M/s Premium furniture
Therefore, 4 rows will be returned by the query.
Question 2 |
Consider the following two tables and four queries in SQL.
Book (isbn, bname), Stock (isbn, copies)Query 1: SELECT B.isbn, S.copies FROM Book B INNER JOIN Stock S ON B.isbn = S.isbn; Query 2: SELECT B.isbn, S.copies FROM Book B LEFT OUTER JOIN Stock S ON B.isbn = S.isbn; Query 3: SELECT B.isbn, S.copies FROM Book B RIGHT OUTER JOIN Stock S ON B.isbn = S.isbn; Query 4: SELECT B.isbn, S.copies FROM Book B FULL OUTER JOIN Stock S ON B.isbn = S.isbn;
Which one of the queries above is certain to have an output that is a superset of the outputs of the other three queries?
Query 1
| |
Query 2 | |
Query 3 | |
Query 4 |
Book (isbn, bname)
Stock (isbn, copies)
isbn is a primary key of Book and isbn is a foreign key of stock referring to Book table.
For example:

Query 1:
INNER JOIN keyword selects records that have matching values in both tables (Book and Stock).

So, the result of Query 1 is,

Query 2:
The LEFT OUTER JOIN keyword returns all records from the left table (Book) and the matched records from the right table (Stock).
The result is NULL from the right side, if there is no match.

So, the result of Query 2 is,

Query 3:
The RIGHT OUTER JOIN keyword returns all records from the right table (Stock), and the matched records from the left table(BOOK).
The result is NULL from the left side, when there is no match.


Query 4:
The FULL OUTER JOIN keyword return all records when there is a match in either left (Book) or right (Stock) table records.

So, the result of Query 4 is,

Therefore, from the result of above four queries, a superset of the outputs of the Query 1, Query 2 and Query 3 is Query 4.
Note:
If we take isbn as a primary key in both the tables Book and Stock and foreign key, in one of the tables then also will get option (D) as the answer.
Question 3 |
Consider a database that has the relation schema EMP (EmpId, EmpName, and DeptName). An instance of the schema EMP and a SQL query on it are given below.
The output of executing the SQL query is ___________.
2.6 | |
2.7 | |
2.8 | |
2.9 |

⇾ We start evaluating from the inner query.
The inner query forms DeptName wise groups and counts the DeptName wise EmpIds.
⇾ In inner query DeptName, Count(EmpId) is the alias name DeptName, Num.
So, the output of the inner query is,

The outer query will find the
Avg(Num) = (4+3+3+2+1)/5 = 2.6
Question 4 |
Consider the following database table named top_scorer.

SELECT ta.player FROM top_scorer AS ta WHERE ta.goals > ALL (SELECT tb.goals FROM top_scorer AS tb WHERE tb.country = 'Spain') AND ta.goals > ANY (SELECT tc.goals FROM top_scorer AS tc WHERE tc.country = 'Germany')
The number of tuples returned by the above SQL query is _____.
7 | |
8 | |
9 | |
10 |

In the given database table top_scorer no players are there from ‘Spain’.
So, the query (1) results 0 and ALL (empty) is always TRUE.
The query (2) selects the goals of the players those who are belongs to ‘Germany’.
So, it results in ANY (16, 14, 11, 10).
So, the outer most query results the player names from top_scorer, who have more goals.
Since, the minimum goal by the ‘Germany’ player is 10, it returns the following 7 rows.

Question 5 |
Consider the following database table named water_schemes :

The number of tuples returned by the following SQL query is _________.
with total(name, capacity) as select district_name, sum(capacity) from water_schemes group by district_name with total_avg(capacity) as select avg(capacity) from total select name from total, total_avg where total.capacity ≥ total_avg.capacity
2 | |
3 | |
4 | |
5 |
The name assigned to the sub-query is treated as though it was an inline view or table.
• First group by district name is performed and total capacities are obtained as following:

• Then average capacity is computed, Average Capacity = (20 + 40 + 30 + 10)/4 = 100/4 = 25
• Finally, 3rd query will be executed and it's tuples will be considered as output, where name of district and its total capacity should be more than or equal to 25.
• Then average capacity is computed,
Average Capacity = (20 + 40 + 30 + 10)/4 = 100/4 = 25
• Finally, 3rd query will be executed and it's tuples will be considered as output, where name of district and its total capacity should be more than or equal to 25.

Question 6 |
the selection operation in relational algebra | |
the selection operation in relational algebra, except that SELECT in SQL retains duplicates
| |
the projection operation in relational algebra | |
the projection operation in relational algebra, except that SELECT in SQL retains duplicates
|
Question 7 |

SELECT S. Student_Name, sum(P.Marks) FROM Student S, Performance P WHERE S.Roll_No = P.Roll_No GROUP BY S.Student_NameThe number of rows that will be returned by the SQL query is _________
2 | |
3 | |
4 | |
5 |

Question 8 |
Cinema (theater, address, capacity)Which of the following options will be needed at the end of the SQL query
SELECT P1. address FROM Cinema P1Such that it always finds the addresses of theaters with maximum capacity?
WHERE P1.capacity >= All (select P2.capacity from Cinema P2) | |
WHERE P1.capacity >= Any (select P2.capacity from Cinema P2) | |
WHERE P1.capacity > All (select max(P2.capacity) from Cinema P2) | |
WHERE P1.capacity > Any (select max(P2.capacity) from Cinema P2) |
So the theatres which are having maximum capacity will satisfy the condition.
Question 9 |
S1: A foreign key declaration can always be replaced by an equivalent check assertion in SQL. S2: Given the table R(a,b,c) where a and b together form the primary key, the following is a valid table definition. CREATE TABLE S ( a INTEGER, d INTEGER, e INTEGER, PRIMARY KEY (d), FOREIGN KEY (a) references R)Which one of the following statements is CORRECT?
S1 is TRUE and S2 is FALSE. | |
Both S1 and S2 are TRUE. | |
S1 is FALSE and S2 is TRUE. | |
Both S1 and S2 are FALSE. |
Using a check constraint, we can have the same effect as foreign key while adding elements to the child table. But while deleting elements from the parent table the referential integrity constraint is no longer valid. So, a check constraint cannot replace a foreign key.
S2: False:
Foreign key in one table should be defined as a primary key in other table. In above table definition, table S has a foreign key that refers to field ‘a’ of R. The field ‘a’ in table S is part of the primary key and part of the key cannot be declared as a foreign key.
Question 10 |
employees(emp-id, first-name, last-name, hire-date, dept-id, salary) departments(dept-id, dept-name, manager-id, location-id)You want to display the last names and hire dates of all latest hires in their respective departments in the location ID 1700. You issue the following query:
SQL> SELECT last-name, hire-date FROM employees WHERE (dept-id, hire-date) IN ( SELECT dept-id, MAX(hire-date) FROM employees JOIN departments USING(dept-id) WHERE location-id = 1700 GROUP BY dept-id); What is the outcome?
It executes but does not give the correct result. | |
It executes and gives the correct result. | |
It generates an error because of pairwise comparison. | |
It generates an error because the GROUP BY clause cannot be used with table joins in a subquery. |
Question 11 |
select * from R where a in (select S.a from S)
select R.* from R,S where R.a=S.a | |
select distinct R.* from R,S where R.a=S.a | |
select R.* from R,(select distinct a from S) as S1 where R.a=S1.a | |
select R.* from R,S where R.a=S.a and is unique R |
Question 12 |
Names of all the employees with at least one of their customers having a ‘GOOD’ rating. | |
Names of all the employees with at most one of their customers having a ‘GOOD’ rating. | |
Names of all the employees with none of their customers having a ‘GOOD’ rating. | |
Names of all the employees with all their customers having a ‘GOOD’ rating. |

The inner query i.e., ② represents all customers having other than ‘GOOD’ while the entire query represents name of all employees with all their customers having a ‘good rating’.
Question 13 |
P and R | |
P and S | |
Q and R | |
Q and S |
The HAVING Clause enables you to specify conditions that filter which group results appear in the results. The WHERE clause places conditions on the selected columns, whereas the HAVING clause places conditions on groups created by the GROUP BY clause. So, we cannot use HAVING clause without GROUP BY clause.
Question 14 |

SELECT A.id FROM A WHERE A.age > ALL (SELECT B.age FROM B WHERE B. name = "arun")
4 | |
3 | |
0 | |
1 |

First query (2) will be executed and 0 (no) rows will be selected because in relation B there is no Name ‘Arun’.
The outer query (1) results the follow and that will be the result of entire query now. (Because inner query returns 0 rows).

Question 15 |
Borrower Bank_Manager Loan_Amount Ramesh Sunderajan 10000.00 Suresh Ramgopal 5000.00 Mahesh Sunderajan 7000.00What is the output of the following SQL query?
SELECT Count(*) FROM ( ( SELECT Borrower, Bank_Manager FROM Loan_Records) AS S NATURAL JOIN ( SELECT Bank_Manager, Loan_Amount FROM Loan_Records) AS T );
3 | |
9 | |
5 | |
6 |

Question 16 |
SELECT Y FROM T WHERE X=7;`
127
| |
255 | |
129 | |
257 |

Question 17 |
Table: Passenger pid pname age ----------------- 0 Sachin 65 1 Rahul 66 2 Sourav 67 3 Anil 69 Table : Reservation pid class tid --------------- 0 AC 8200 1 AC 8201 2 SC 8201 5 AC 8203 1 SC 8204 3 AC 8202What pids are returned by the following SQL query for the above instance of the tables?
SLECT pid FROM Reservation , WHERE class ‘AC’ AND EXISTS (SELECT * FROM Passenger WHERE age > 65 AND Passenger. pid = Reservation.pid)
1, 0 | |
1, 2 | |
1, 3 | |
1, 5 |

― 1, 3 Pids are returned
Question 18 |
Find the names of all suppliers who have supplied a non-blue part.
| |
Find the names of all suppliers who have not supplied a non-blue part. | |
Find the names of all suppliers who have supplied only blue parts.
| |
Find the names of all suppliers who have not supplied only blue parts.
|



If we execute the given query the output will be S3 and S4 i.e., names of all suppliers who didn’t supply blue parts which is option (A).
Option (D) says names of suppliers who didn’t supply only blue parts that means, supplier should supply all other parts for sure and shouldn’t supply blue part.
Question 19 |
SELECT sch-name, COUNT (*) FROM School C, Enrolment E, ExamResult R WHERE E.school-id = C.school-id AND E.examname = R.examname AND E.erollno = R.erollno AND R.marks = 100 AND S.school-id IN (SELECT school-id FROM student GROUP BY school-id HAVING COUNT (*) > 200) GROUP By school-id /* Add code here. Remove these lines if not writing code */ |
for each school with more than 200 students appearing in exams, the name of the school and the number of 100s scored by its students | |
for each school with more than 200 students in it, the name of the school and the number of 100s scored by its students | |
for each school with more than 200 students in it, the name of the school and the number of its students scoring 100 in at least one exam | |
nothing; the query has a syntax error
|
Question 20 |
Query1: select A.customer, count(B.customer) from account A, account B where A.balance <=B.balance group by A.customer Query2: select A.customer, 1+count(B.customer) from account A, account B where A.balance < B.balance group by A.customerConsider these statements about Query1 and Query2.
1. Query1 will produce the same row set as Query2 for some but not all databases. 2. Both Query1 and Query2 are correct implementation of the specification 3. Query1 is a correct implementation of the specification but Query2 is not 4. Neither Query1 nor Query2 is a correct implementation of the specification 5. Assigning rank with a pure relational query takes less time than scanning in decreasing balance order assigning ranks using ODBC.Which two of the above statements are correct?
2 and 5
| |
1 and 3
| |
1 and 4
| |
3 and 5
|
The customer with largest balance gets rank 1. Ties are broken with ranks are skipped.
So, both queries may doesn’t give same output. Statement 4 is correct.
Question 21 |
Query1: select student from enrolled where student in (select student from paid) Query2: select student from paid where student in (select student from enrolled) Query3: select E.student from enrolled E, paid P where E.student = P.student Query4: select student from paid where exists (select * from enrolled where enrolled.student = paid.student)Which one of the following statements is correct?
All queries return identical row sets for any database.
| |
Query2 and Query4 return identical row sets for all databases but there exist databases for which Query1 and Query2 return different row sets.
| |
There exist databases for which Query3 returns strictly fewer rows than Query2.
| |
There exist databases for which Query4 will encounter an integrity violation at runtime.
|

Query1 : Output
abcd
abcd
PQRS
Query 2 : Output
abcd
PQRS
Query 3 : Output
abcd
PQRS
Query 4 : Output
abcd
PQRS
Query 2 & Query 4 gives same results but Query 1 & Query 3 gives different results.
Question 22 |


Karthikeyan, Boris | |
Sachin, Salman | |
Karthikeyan, Boris, Sachin | |
Schumacher, Senna
|
did = {22, 22, 31, 31, 64}
For colour = "Green"
did = {22, 31, 74}
Intersection of Red and Green will be = {22, 31}, which is Karthikeyan and Boris.
Question 23 |

36 - 40 | |
44 - 48 | |
60 - 64 | |
100 - 104 |
red did : 22, 31, 64
green did : 22, 31, 74
(6) for intersection
(1) for searching 22 in driver relation, and (3) for searching 31.
Total: 38 + 6 + 4 = 48
Question 24 |
select title from book as B where (select count(*) from book as T where T.price > B.price) < 5
Titles of the four most expensive books
| |
Title of the fifth most inexpensive book
| |
Title of the fifth most expensive book
| |
Titles of the five most expensive books
|
The where clause of outer query will be true for 5 most expensive books.
Question 25 |
T1 |
Update salesinfo Set commission = commission * 1.02 Where commission < = 50000; |
T2 |
Update salesinfo Set commission = commission * 1.04 Where commission > 50000 and commission is < = 100000; |
T3 |
Update salesinfo Set commission = commission * 1.06 Where commission > 100000; |
Execute T1 followed by T2 followed by T3 | |
Execute T2, followed by T3; T1 running concurrently throughout | |
Execute T3 followed by T2; T1 running concurrently throughout | |
Execute T3 followed by T2 followed by T1
|
In other cases some people will get two times increment, for example,
if we have T1 followed by T2 and if initial commission is 49500, then he is belonging to <50000.
Hence, 49500 * 1.02 = 50490.
Now again he is eligible for second category. So, he will get again increment as,
50490 * 1.04 = 52509.6
So he will get increment two times, but he is eligible for only one slab of commission.
Question 26 |
ROLL | NAME | HOSTEL | MARKS |
---|---|---|---|
1798 | Manoj Rathod | 7 | 95 |
2154 | Soumic Banerjee | 5 | 68 |
2369 | Gumma Reddy | 7 | 86 |
2581 | Pradeep Pendse | 6 | 92 |
2643 | Suhas Kulkarni | 5 | 78 |
2711 | Nitin Kadam | 8 | 72 |
2872 | Kiran Vora | 5 | 92 |
2926 | Manoj Kunkalikar | 5 | 94 |
2959 | Hemant Karkhanis | 7 | 88 |
3125 | Rajesh Doshi | 5 | 82 |
ROLL | HOBBYNAME |
---|---|
1798 | chess |
1798 | music |
2154 | music |
2369 | swimming |
2581 | cricket |
2643 | chess |
2643 | hockey |
2711 | volleyball |
2872 | football |
2926 | cricket |
2959 | photography |
3125 | music |
3125 | chess |
select hostel from student natural join hobby where marks > = 75 and roll between 2000 and 3000;Relations S and H with the same schema as those of these two tables respectively contain the same information as tuples. A new relation S’ is obtained by the following relational algebra operation: S’ = ∏hostel ((σs.roll = H.roll (σmarks > 75 and roll > 2000 and roll < 3000 (S)) X (H)) The difference between the number of rows output by the SQL statement and the number of tuples in S’ is
6 | |
4 | |
2 | |
0 |

Total 7 rows are selected.
Where in relational algebra only distinct values of hostels are selected,i.e., 5, 6, 7 (3 rows).
∴ Answer is 7 - 3 =4
Question 27 |
Select distinct STMP.supplierid From Supply as STMP Where not unique (Select ITMP.supplierid From Inventory, Supply as ITMP Where STMP.supplierid = ITMP.supplierid And ITMP.itemcode = Inventory.itemcode And Inventory.warehouse = 'Nagpur');For the warehouse at Nagpur, this query will find all suppliers who
do not supply any item | |
supply exactly one item | |
supply one or more items | |
supply two or more items |
Question 28 |
the average salary is more than the average salary in the company
| |
the average salary of male employees is more than the average salary of all male employees in the company
| |
the average salary of male employees is more than the average salary of employees in the same department
| |
the average salary of male employees is more than the average salary in the company
|
This results the employees who having the salary more than the average salary.
Sex = M
Selects the Male employees whose salary is more than the average salary in the company.
Question 29 |
Insert into department values (1, 'Mathematics') Insert into department values (2, 'Physics') Insert into student values (l, 'Navin', 1) Insert into student values (2, 'Mukesh', 2) Insert into student values (3, 'Gita', 1)How many rows and columns will be retrieved by the following SQL statement?
Select * from student, department
0 row and 4 columns | |
3 rows and 4 columns | |
3 rows and 5 columns | |
6 rows and 5 columns |
rows = 3 * 2 = 6
Columns = 3 + 2 = 5
Question 30 |
roll no. | marks |
1 | 10 |
2 | 20 |
3 | 30 |
4 | Null |
Update T1 set marks = marks + 5 Select avg(marks) from T1What is the output of the select statement?
18.75 | |
20 | |
25 | |
NULL |
(15+25+35)/3 = 25
Question 31 |
select distinct al, a2,........., an from r1, r2,........, rm where PFor an arbitrary predicate P, this query is equivalent to which of the following relational algebra expressions ?
![]() | |
![]() | |
![]() | |
![]() |
Question 32 |
Students: (Roll_number, Name, Date_of_birth) Courses: (Course number, Course_name, Instructor) Grades: (Roll_number, Course_number, Grade)
select distinct Name from Students, Courses, Grades where Students. Roll_number = Grades.Roll_number and Courses.Instructor = Korth and Courses.Course_number = Grades.Course_number and Grades.grade = AWhich of the following sets is computed by the above query?
Names of students who have got an A grade in all courses taught by Korth
| |
Names of students who have got an A grade in all courses
| |
Names of students who have got an A grade in at least one of the courses taught by Korth
| |
in none of the above |
Question 33 |
r has no duplicates and s is non-empty | |
r and s have no duplicates | |
s has no duplicates and r is non-empty | |
r and s have the same number of tuples |
Question 34 |
In SQL, relations can contain null values, and comparisons with null values are treated as unknown. Suppose all comparisons with a null value are treated as false. Which of the following pairs is not equivalent?
x = 5 not AND (not (x = 5) | |
x = 5 AND x > 4 and x < 6, where x is an integer | |
x ≠ 5 AND not (x = 5) | |
None of the above |
Question 36 |
An SQL query automatically eliminates duplicates | |
An SQL query will not work if there are no indexes on the relations | |
SQL permits attribute names to be repeated in the same relation | |
None of the above |
→ If there are no indexes on the relation SQL, then also it works.
→ SQL does not permit 2 attributes to have same name in a relation.
Question 37 |
A tuple (z,w) with z > y is deleted | |
A tuple (z,w) with z > x is deleted | |
A tuple (z,w) with w < x is deleted | |
The deletion of (x,y) is prohibited |