SQL questions

Q54

GATE CS 2014 CS-2Relational QueriesMCQ2 marks−2/3 if wrong
SQL allows duplicate tuples in relations, and correspondingly defines the multiplicity of tuples in the result of joins. Which one of the following queries always gives the same answer as the nested query shown below:
select * from R where a in (select S.a from S)
Show answer without attempting

Answer: C

Q54

GATE CS 2014 CS-3Relational QueriesMCQ2 marks−2/3 if wrong
Consider the following relational schema:

employee(empId,empName,empDept)
customer(custId,custName,salesRepId,rating)

salesRepId is a foreign key referring to empId of the employee relation. Assume that each employee makes a sale to at least one customer. What does the following query return?
SELECT empName
FROM employee E
WHERE NOT EXISTS (SELECT custId
                  FROM customer C
                  WHERE C.salesRepId = E.empId
                  AND C.rating <> 'GOOD');
Show answer without attempting

Answer: D

Q54

GATE CS 2014 CS-1Relational QueriesMCQ2 marks−2/3 if wrong
Given the following schema:
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?
Show answer without attempting

Answer: B

0/30 correct0 marks

Related topics in Relational Queries