SQL
GATE CSE & IT · 33 questions across 19 years (1998-2025) · 48% recurrence rate
Recurrence sparkline
1998–2025Difficulty mix
Question types
All 33 questions on SQL
Consider the following relational schema: Students ($$\mathrm{\underline {rollno:integer}}$$, name: string, age: integer, cgpa: real) Courses ($$\mathrm{\underline {courseno:integer}}$$, cname: string, credits: integer)...
Consider the following table named Student in a relational database. The primary key of this table is rollNum. Student rollNum name gender marks 1 Naman M 62 2 Aliya F 70 3 Aliya F 80 4 James M 82 5 Swati F 65 The SQL qu...
The relation scheme given below is used to store information about the employees of a company, where empId is the key and deptId indicates the department to which the employee is assigned. Each employee is assigned to ex...
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...
Consider the following database table named $$water$$_$$schemes :$$ water_schemes scheme_no district_name capacity 1 Ajmer 20 1 Bikaner 10 2 Bikaner 10 3 Bikaner 20 1 Churu 10 2 Churu 20 1 Dungargarh 10 The number of tup...
Consider the following relation: Student Roll_No Student_Name 1 Raj 2 Rohit 3 Raj Performance Roll_No Course Marks 1 Math 80 1 English 70 2 Math 75 3 English 80 2 Physics 65 3 Math 80 Consider the following SQL query. SE...
SELECT operation in SQL is equivalent to
Consider the following relation $$\,\,\,\,\,\,\,\,$$ Cinema(theater, address, capacity) Which of the following options will be needed at the end of the $$SQL$$ query $$\,\,\,\,\,\,\,\,$$ SELECT $$P1.$$address $$\,\,\,\,\...
Given the following statements: 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 v...
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 em...
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 hi...
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: Se...
Which of the following statements are TRUE about an SQL query? P: An SQL query can contain a HAVING clause even if it does not have a GROUP BY clause Q: An SQL query can contain a HAVING clause only if it has a GROUP BY...
Database table by name Loan_Records is given below. Borrower Bank_Manager Loan_Amount Ramesh Sunderajan 10000.00 Suresh Ramgopal 5000.00 Mahesh Sunderajan 7000.00 What is the output of the following SQL query? SELECT cou...
Consider a database table T containing two columns X and Y each of type integer. After the creation of the table, one record (X = 1, Y = 1) is inserted in the table. Let MX and MY denote the respective maximum values of...
A relational schema for a train reservation database is given below: Passenger ( pid, pname, age) Reservation (pid, cass, tid) Table: Passenger pid pname age 0 'Sachin' 65 1 'Rahul' 66 2 'Sourav' 67 3 'Anil' 69 Table: Re...
Consider The Following Relational Scheme Student ( school-id, sch-roll-no , sname, saddress) School ( school-id , sch-name, sch-address, sch-phone) Enrolment ( school-id, sch-roll-no, erollno, examname) ExamResult ( Erol...
Consider the table employee(empId, name, department, salary) and the two queries Q 1 , Q 2 below. Assuming that department 5 has more than one employee, and we want to find the employees who get higher salary than anyone...
Consider the relation "enrolled (student, course)" in which (student, course) is the primary key, and the relation "paid (student, amount)" where student is the primary key. Assume no null values and no foreign keys or i...
Consider a database with three relation instances shown below. The primary keys for the Drivers and Cars relation are Did and cid respectively and the records are stored in ascending order of these primary keys as given...
Consider the relation account (customer, balance) where customer is a primary key and there are no null values. We would like to rank customers according to decreasing balance. The customer with the largest balance gets...
In an inventory management system implemented at a trading corporation, there are several tables designed to hold all the information. Amongst these, the following two tables hold information on which items are supplied...
The relation book (title, price) contains the titles and prices of different books. Assuming that no two books have the same price, what does the following SQL query list? Select title From book as B Where (select count(...
A table ‘student’ with schema (roll, name, hostel, marks), and another table ‘hobby’ with schema (roll, hobbyname) contains records as shown below: Table: student Roll Name Hostel Marks 1798 Manoj Rathod 7 95 2154 Soumic...
A relational database contains two table student and department in which student table has columns roll_no, name and dept_id and department table has columns dept_id and detp_name . the following insert statements were e...
Consider two tables in a relational database with columns and rows as follows: Table: Student Roll_no Name Dept_id 1 ABC 1 2 DEF 1 3 GHI 2 4 JKL 3 Table: Department Dept_id Dept_name 1 A 2 B 3 C Roll_no is the primary ke...
The employee information in a company is stored in the relation Employee (name, sex, salary, deptName) Consider the following SQL query Select deptName From Employee Where sex = ‘M’ Group by deptName Having avg(salary) >...
Consider the set of relations shown below and the SQL query that follows. Students: (Roll_number, Name, Date_of_birth) Courses: (Course number, Course_name, Instructor) Grades: (Roll_number, Course_number, Grade) Select...
Given relations r( w, x ) and s( y, z ), the result of select distinct w,x from r, s; is guaranteed to be same as r, provided
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?
Which of the following is/are correct?
Consider the set of relations EMP (Employee-no, Dept-no, Employee-name, Salary) DEPT (Dept-no, Dept-name, Location) Write an SQL query to: (a) Find all employee names who work in departments located at "Calcutta" and who...
Suppose we have a database consisting of the following three relations. FREQUENTS (student, parlor) giving the parlors each student visits. SERVES (parlor, ice-cream) indicating what kind of ice-creams each parlor serves...