GATE CSE SQL PYQs
In GATE CS, SQL is tested through a balanced mix of declarative query semantics, relational-algebra correspondence, subquery evaluation (correlated, nested, and… Read the guide
- Questions
- 17
- Asked
- since 2011
- Total marks
- 28
- Marks / paper
- 1.1
17 GATE CSE SQL PYQs with solutions, from Databases. Browse all GATE CSE PYQs.
Questions
Every official paper that asked this topic, newest first.
- GATE CSE 2025 Set 1 · Q55Consider the following database tables of a sports league.
player(pid, pname, age)team(tid, tname, city, cid)coach(cid, cname)members(pid, tid)An instance of the table and an SQL query are given.SELECT MIN(P.age) FROM player P WHERE P.pid IN ( SELECT M.pid FROM team T, coach C, members M WHERE C.cname = 'Mark' AND T.cid = C.cid AND M.tid = T.tid )…NAT2 marksEasyDiagramSolve - GATE CSE 2025 Set 2 · Q54Consider the following relational schema: Students (, name: string, age: integer, cgpa: real) Courses (, cname: string, credits: integer) Enrolled (, , grade:…MSQ2 marksMediumSolve
- GATE CSE 2023 · Q61Consider the following table named
Studentin a relational database. The primary key of this table isrollNum. The SQL query below is executed on this database.SELECT * FROM Student WHERE gender = 'F' AND marks > 65;The number of rows returned by the query is _________.NAT2 marksEasyDiagramSolve - GATE CSE 2022 · Q56Consider the relational database with the following four schemas and their respective instances. …NAT2 marksMediumDiagramSolve
- GATE CSE 2021 Set 2 · Q31The relation scheme given below is used to store information about the employees of a company, where
empIdis the key anddeptIdindicates the department to which the employee is assigned. Each employee is assigned to exactly one department. …MCQ2 marksEasySolve - GATE CSE 2020 · Q13Consider a relational database containing the following schemas.
The primary key of each table is indicated by underlining 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);…MCQ1 markMediumDiagramSolve - GATE CSE 2018 · Q12Consider the following two tables and four queries in SQL.
Book (, bname), Stock (, 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;…MCQ1 markEasySolve - GATE CSE 2016 Set 2 · Q52Consider the following database table named :
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.capacityNAT2 marksMediumDiagramSolve - GATE CSE 2015 Set 1 · Q7SELECT operation in SQL is equivalent toMCQ1 markEasySolve
- GATE CSE 2015 Set 1 · Q27Consider the following relations:
Consider the following SQL query.
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 ____________.NAT2 marksEasyDiagramSolve - GATE CSE 2015 Set 3 · Q3Consider 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 FROM Cinema P1such that it always finds the addresses of theaters with maximum capacity?MCQ1 markEasySolve - GATE CSE 2014 Set 1 · Q22Given 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 valid table definition. <code>CREATE TABLE S ( a INTEGER, d INTEGER, e INTEGER,…MCQ1 markMediumSolve
- GATE CSE 2014 Set 1 · Q54Given 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.…MCQ2 marksMediumSolve - GATE CSE 2014 Set 3 · Q54Consider the following relational schema:
employee(empId, empName, empDept)customer(custId, custName, salesRepId, rating)salesRepIdis a foreign key referring toempIdof the employee relation. Assume that each employee makes a sale to at least one customer. What…MCQ2 marksMediumSolve - GATE CSE 2012 · Q15Which 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 clause R : All attributes used in the GROUP BY clause must appear in the SELECT clause S : Not…MCQ1 markMediumSolve
- GATE CSE 2012 · Q51Common Data for Questions 50 and 51:
Consider the following relations , and :
How many tuples does the result of the following SQL query contain?
SELECT A.Id FROM A WHERE A.Age > ALL (SELECT B.Age FROM B WHERE B.Name = 'Arun')MCQ2 marksMediumDiagramSolve - GATE CSE 2011 · Q32Consider 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 X and Y among all records in the table at any point in time. Using MX and MY, new records…MCQ2 marksMediumSolve
What GATE tests in SQL
Concepts, patterns, formulas and traps distilled from past papers.
In GATE CS, SQL is tested through a balanced mix of declarative query semantics, relational-algebra correspondence, subquery evaluation (correlated, nested, and universal quantification), and instance-level tracing. Questions range from conceptual integrity rules (DDL constraints, FOREIGN KEY targets, GROUP BY/HAVING rules) to practical computation of output row counts and aggregate values on small database instances. Recent papers strongly emphasize NAT execution traces and multi-correct (MSQ) equivalent query formulations.
Core concepts
- Correlated vs Uncorrelated Subqueries
- Quantified comparison predicates (ALL, ANY, IN, EXISTS, NOT EXISTS)
- Relational Division in SQL (NOT EXISTS with EXCEPT / NOT EXISTS with correlated condition)
- GROUP BY, HAVING, and aggregate functions (COUNT, SUM, AVG, MIN, MAX)
- Bag semantics of SELECT vs Set semantics of Relational Algebra projection
- Join semantics (INNER JOIN, NATURAL JOIN, LEFT/RIGHT/FULL OUTER JOIN)
- Integrity constraints (PRIMARY KEY, composite keys, FOREIGN KEY referential constraints, CHECK)
- Common Table Expressions (WITH clause) and multi-column IN predicates
- Pairwise multi-attribute subquery comparison
Recurring question patterns
Instance Tracing and Output/Tuple Counting
CommonNAT2 marks2025, 2023, 2022, 2016Given small relational instances across 1 to 4 tables, evaluate an SQL query involving joins, WHERE filters, CTEs (WITH clause), or subqueries to determine the number of returned tuples or a scalar aggregate value (e.g., MIN, SUM, AVG).
Universal Quantification and Division via Subqueries
CommonMCQ2 marks2022, 2015, 2014, 2012Formulating or interpreting 'for all' queries using
NOT EXISTS (correlated subquery),NOT EXISTS (... EXCEPT ...), or quantified comparison predicates like> ALL,>= ALL.Query Equivalence and Construct Validity
OccasionalMSQ2 marks2025, 2014Identifying which SQL query or queries among multiple options correctly solve an English problem specification, checking valid SQL syntax (e.g., rejecting non-SQL built-ins like SIZEOF) vs NATURAL JOIN vs EXISTS vs scalar COUNT subqueries.
DDL, Integrity Constraints, and SQL Semantics
CommonMCQ1 marks2021, 2018, 2015, 2014Conceptual MCQs testing the requirements of FOREIGN KEY references (must reference primary key / unique candidate key), check assertions vs referential actions, bag semantics of SELECT (projection with duplicates), and outer join containment.
Iterative DML State Simulation
RareMCQ2 marks2011Tracing repeated execution of parameterized INSERT/UPDATE operations tracking aggregate values (MAX/MIN) across generations of records.
Formulas GATE uses
Vacuous Truth of ALL on Empty Sets
Used when an inner subquery inside > ALL or >= ALL returns zero rows, causing the WHERE condition to evaluate to true for every outer tuple.
Relational Division via Double Negation / EXCEPT
Used in SQL queries checking WHERE NOT EXISTS (SELECT ... EXCEPT SELECT ...) or WHERE NOT EXISTS (SELECT ... WHERE NOT ...) to verify that a tuple matches all criteria.
Join Result Set Containment
Used to determine superset/subset relationships among INNER, LEFT, RIGHT, and FULL OUTER joins.
GROUP BY Cardinality
Used to count output tuples when aggregation is performed on joined tables grouped by non-key or key attributes.
Examiner traps in SQL
- Evaluating `> ALL (empty set)` as FALSE or NULL instead of TRUE (vacuous truth).
- Confusing uncorrelated subqueries with correlated subqueries (e.g., computing the company-wide average salary instead of the department average when no correlation condition is present).
- Grouping on a non-unique column (e.g. StudentName) where distinct entities share the same name, resulting in fewer grouped output rows than distinct primary keys.
- Attempting to define a FOREIGN KEY on a proper subset of a composite primary key without a corresponding UNIQUE constraint on that subset.
- Boundary off-by-one errors in WHERE conditions (e.g., treating `>` as `>=`).
- Assuming relational algebra projection retains duplicates, or forgetting that standard SQL SELECT preserves duplicates unless `DISTINCT` is specified.
- Falling for pseudo-SQL keywords like `SIZEOF` instead of standard SQL `COUNT(*)`.
How questions are asked
- Table instance tracing with NAT tuple count output
- Scalar query evaluation (e.g., calculating MIN, MAX, AVG of an SQL query on tables)
- Conceptual validation of SQL statements / DDL rules (MCQ)
- Query equivalence / Multi-query validation (MSQ)
- Subquery logical meaning interpretation (MCQ)
Paper trends
Transitioned from pure conceptual MCQs (relational algebra equivalence, join superset properties) to rigorous NAT row-counting and scalar-value calculation from multi-table instances.
2025, 2023, 2022, 2016, 2015, 2012, 2011
Introduction of advanced query features such as Common Table Expressions (WITH clause), multi-column tuple comparison ((col1, col2) IN (...)), and MSQ query equivalences.
2025, 2016, 2014
Sustained focus on edge cases of subquery logic, such as empty subquery evaluation with ALL/ANY and relational division idioms.
2022, 2015, 2014, 2012
Difficulty notes
Easy: Direct single/two-table SELECT queries with simple WHERE/AND filters, direct relational algebra vs SQL definitions, or basic outer-join containment properties. Medium: Multi-table joins (3–4 tables), queries with CTEs/aggregation comparisons, division queries using double negation/EXCEPT, empty-set quantifier edge cases (> ALL on empty sets), and MSQs discriminating between valid equivalent constructs (EXISTS vs scalar COUNT vs NATURAL JOIN) and invalid syntax.