GateAI

GATE CSE SQL PYQs

Standard yield15.9% of Databases

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.

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, 2016

    Given 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, 2012

    Formulating 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, 2014

    Identifying 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, 2014

    Conceptual 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 marks2011

    Tracing 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

v>ALL(∅)≡TRUE,v=ALL(∅)≡TRUEv > \text{ALL}(\emptyset) \equiv \text{TRUE},\quad v = \text{ALL}(\emptyset) \equiv \text{TRUE}

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

R÷S≡ΠX(R)−ΠX((ΠX(R)×S)−R)≡{x∣(S∖Rx)=∅}R \div S \equiv \Pi_X(R) - \Pi_X((\Pi_X(R) \times S) - R) \equiv \{ x \mid (S \setminus R_x) = \emptyset \}

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

(R⋈S)⊆(R LEFT JOIN S)⊆(R FULL JOIN S)(R \Join S) \subseteq (R \ \text{LEFT JOIN}\ S) \subseteq (R \ \text{FULL JOIN}\ S)

Used to determine superset/subset relationships among INNER, LEFT, RIGHT, and FULL OUTER joins.

GROUP BY Cardinality

∣Output Rows∣=∣Πgroup_attrs(Rfiltered)∣|\text{Output Rows}| = |\Pi_{\text{group\_attrs}}(R_{\text{filtered}})|

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.