Relational Algebra, Tuple Calculus and Sql Short Notes for Gate Cs
Relational Algebra, Tuple Calculus and Sql short notes for GATE CS: 4 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice
Relational Algebra Tuple Calculus and Sql short notes
Quick Revision Grid: TRC to RA
Quick Revision Grid: TRC to RA
Concept
Key Characteristic
Relational Algebra Equivalent
TRC Nature
Declarative ("What" to retrieve)
N/A
RA Nature
Procedural ("How" to retrieve)
N/A
Existential (∃)
"There exists at least one..."
Join (⋈), Intersection (∩)
Universal (∀)
"For all..."
Division (÷)
Negation (¬)
"Does not exist..."
Set Difference (−)
Safe Expression
Guarantees finite result
Variables bound to specific relations
SQL Queries: Rapid Revision Checklist
SQL Queries: Rapid Revision Checklist
Execution Order: FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY.
WHERE vs HAVING:WHERE filters rows (no aggregates). HAVING filters groups (uses aggregates).
COUNT Trap:COUNT(*) includes NULL rows. COUNT(col) ignores NULL values in col.
Outer Join: Unmatched rows are preserved and padded with NULL.
Empty Aggregates:AVG, SUM, MIN, MAX on empty sets return NULL, not 0.
Universal Quantification: "For all" is implemented as NOT EXISTS ( ... NOT EXISTS ... ).
GROUP BY Rule: Every column in SELECT must be in GROUP BY or inside an aggregate function.
Relational Algebra: Rapid Revision Checklist
Rapid Revision Checklist
Self-Join Requirement
Always use the rename operator (ρ) to create distinct aliases before joining a relation with itself.
Division Meaning
Answers "for all" or "contains every" queries.
Division Formula
R÷S=ΠX(R)−ΠX((ΠX(R)×S)−R), where X are attributes in R but not in S.
Division Schema
Attributes(R÷S)=Attributes(R)−Attributes(S).
"At Least N" Pattern
Requires joining N copies of the relation, which demands exactly N−1 cross product/join operations.
Distinctness in Self-Join
When finding "at least N" distinct entities, explicitly enforce inequality (=) on the primary keys across all N aliases.
1 more card in this chapter
Try a question
Answer it here to see how it works. Nothing is recorded until you sign in.
Question 1
Level 1: Warm-up
Which of the following SQL queries is valid according to the GROUP BY SELECT list constraint?
Question 2
Level 1: Warm-up
Consider the following Assertion (A) and Reason (R) regarding SQL filtering:
Assertion (A): In the query `SELECT dept_id, COUNT(*) FROM emp WHERE salary > 50000 GROUP BY dept_id HAVING COUNT(*) > 5`, the `HAVING` clause filters the groups after aggregation.
Reason (R): The `WHERE` clause can use the aggregate function `COUNT(*)` to filter rows before grouping.
Question 3
Level 1: Warm-up
Consider the SQL query: SELECT country, MAX(population) FROM cities GROUP BY continent;. This query violates a fundamental SQL constraint. Which of the following statements correctly identifies the violated constraint?
Question 4
Level 1: Warm-up
Consider the following Assertion (A) and Reason (R) regarding SQL clause evaluation:
Assertion (A): The `WHERE` clause is evaluated before the `GROUP BY` clause in the logical execution order.
Reason (R): The `WHERE` clause can contain aggregate functions like `SUM(salary)` to filter rows before grouping.
Question 5
Level 1: Warm-up
Which of the following statements is TRUE regarding the GROUP BY SELECT list constraint in standard SQL?
Question 6
Level 1: Warm-up
Consider the following Assertion (A) and Reason (R) regarding SQL clause evaluation:
Assertion (A): A condition like `SUM(salary) > 100000` can be placed in the `WHERE` clause to filter rows before grouping.
Reason (R): The `WHERE` clause operates on individual rows before any aggregation or grouping takes place, so aggregate results are not yet available.
Question 7
Level 1: Warm-up
Let R(A,B) contain exactly 20 tuples with ΠA(R) yielding exactly 6 distinct values. Let S(B) contain exactly 4 tuples. In the standard construction of division, let T1=ΠA(R)×S and T2=T1−R. Suppose T2 contains exactly 8 tuples and ΠA(T2) yields exactly 2 distinct values. The number of tuples in R÷S is __________.
Question 8
Level 1: Warm-up
A relation has 10 tuples. The attribute X has some NULL values. What is the MAXIMUM number of NULL values in X such that AVG(X) does not return NULL?
Question 9
Level 1: Warm-up
A SQL query contains the clauses SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY. If a student assumes the database executes these clauses in the exact order they are written, how many of these clauses will actually be executed at a different position in the logical execution order?
Question 10
Level 1: Warm-up
A relation has 20 tuples. The attribute bonus contains some NULL values. What is the MAXIMUM possible difference between the results of COUNT(*) and COUNT(bonus) for this relation?
Free preview ends here
Login to view the complete short notes
Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.
Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.
Built around you, not around a syllabus PDF
Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.
Revision that hits your weak spots
We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.
Questions calibrated to the real exam
Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.
Notes written for recall, not for volume
Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.
One place for everything
Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.
Honest progress
No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.
Unlock the whole course
Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.
Relational Algebra, Tuple Calculus and Sql Short Notes for GATE CS
Relational Algebra, Tuple Calculus and Sql short notes for GATE CS: 4 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice questions.
Quick Revision Grid: TRC to RA
Quick Revision Grid: TRC to RA
Concept
Key Characteristic
Relational Algebra Equivalent
TRC Nature
Declarative ("What" to retrieve)
N/A
RA Nature
Procedural ("How" to retrieve)
N/A
Existential (∃)
"There exists at least one..."
Join (⋈), Intersection (∩)
Universal (∀)
"For all..."
Division (÷)
Negation (¬)
"Does not exist..."
Set Difference (−)
Safe Expression
Guarantees finite result
Variables bound to specific relations
SQL Queries: Rapid Revision Checklist
SQL Queries: Rapid Revision Checklist
Execution Order: FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY.
WHERE vs HAVING:WHERE filters rows (no aggregates). HAVING filters groups (uses aggregates).
COUNT Trap:COUNT(*) includes NULL rows. COUNT(col) ignores NULL values in col.
Outer Join: Unmatched rows are preserved and padded with NULL.
Empty Aggregates:AVG, SUM, MIN, MAX on empty sets return NULL, not 0.
Universal Quantification: "For all" is implemented as NOT EXISTS ( ... NOT EXISTS ... ).
GROUP BY Rule: Every column in SELECT must be in GROUP BY or inside an aggregate function.
Relational Algebra: Rapid Revision Checklist
Rapid Revision Checklist
Self-Join Requirement
Always use the rename operator (ρ) to create distinct aliases before joining a relation with itself.
Division Meaning
Answers "for all" or "contains every" queries.
Division Formula
R÷S=ΠX(R)−ΠX((ΠX(R)×S)−R), where X are attributes in R but not in S.
Division Schema
Attributes(R÷S)=Attributes(R)−Attributes(S).
"At Least N" Pattern
Requires joining N copies of the relation, which demands exactly N−1 cross product/join operations.
Distinctness in Self-Join
When finding "at least N" distinct entities, explicitly enforce inequality (=) on the primary keys across all N aliases.
Cardinality Estimation: Rapid Revision Checklist
Rapid Revision Checklist
Your quick reference for cardinality estimation formulas and rules.
1
Equality:TσA=v(R)=V(A,R)TR
2
Range (A>v):TR×max(A)−min(A)max(A)−v
3
AND (Independent):TRTσC1(R)×TσC2(R)
4
OR:TC1+TC2−TC1∧C2
5
Precondition: Multiplication rules require attributes to be independently distributed.
6
Distinct Values: For integer ranges [min,max], V=max−min+1.
Relational Algebra, Tuple Calculus and Sql: Solved Questions with Step-by-Step Explanations (10 Problems)
Question 1 · DatabasesMCQ
Which of the following SQL queries is valid according to the GROUP BY SELECT list constraint?
A.
SELECT dept_id, name, MAX(salary) FROM emp GROUP BY dept_id
B.
SELECT dept_id, MAX(salary) FROM emp GROUP BY dept_id
C.
SELECT name, MAX(salary) FROM emp GROUP BY dept_id
D.
SELECT dept_id, name, salary FROM emp GROUP BY dept_id
Correct Answer:
B
Step-by-Step Solution
Key idea: This is a bounding question on the strict syntactic rules of the GROUP BY clause.
Step 1: Recall the GROUP BY SELECT list constraint. Every column in the SELECT list must either be included in the GROUP BY clause or be an argument to an aggregate function.
Step 2: Evaluate Option A: name is in SELECT but not in GROUP BY and not aggregated. (Invalid)
Step 3: Evaluate Option B: dept_id is in GROUP BY. MAX(salary) is aggregated. (Valid)
Step 4: Evaluate Option C: name is in SELECT but not in GROUP BY and not aggregated. (Invalid)
Step 5: Evaluate Option D: name and salary are in SELECT but not in GROUP BY and not aggregated. (Invalid)
Answer: SELECT dept_id, MAX(salary) FROM emp GROUP BY dept_id
Question 2 · DatabasesMCQ
Consider the following Assertion (A) and Reason (R) regarding SQL filtering:
Assertion (A): In the query `SELECT dept_id, COUNT(*) FROM emp WHERE salary > 50000 GROUP BY dept_id HAVING COUNT(*) > 5`, the `HAVING` clause filters the groups after aggregation.
Reason (R): The `WHERE` clause can use the aggregate function `COUNT(*)` to filter rows before grouping.
A.
Both A and R are true and R is the correct explanation of A.
B.
Both A and R are true but R is NOT the correct explanation of A.
C.
A is true but R is false.
D.
A is false but R is true.
Correct Answer:
C
Step-by-Step Solution
Key idea: This is a construction question testing the fundamental difference between WHERE and HAVING.
Step 1: Analyze Assertion (A). The HAVING clause is specifically designed to filter groups after the GROUP BY aggregation has occurred. Thus, A is true.
Step 2: Analyze Reason (R). The WHERE clause filters individual rows BEFORE any grouping or aggregation happens. It cannot contain aggregate functions like COUNT(*). Thus, R is false.
Step 3: Since A is true and R is false, the correct option is "A is true but R is false".
Answer: A is true but R is false.
Question 3 · DatabasesMCQ
Consider the SQL query: SELECT country, MAX(population) FROM cities GROUP BY continent;. This query violates a fundamental SQL constraint. Which of the following statements correctly identifies the violated constraint?
A.
country is in the SELECT list but is neither in the GROUP BY clause nor inside an aggregate function.
B.
continent is in the GROUP BY clause but is missing from the SELECT list.
C.
MAX(population) cannot be used in the SELECT list when grouping by continent.
D.
country must be placed inside the MAX() function because it is a string attribute.
Correct Answer:
A
Step-by-Step Solution
Key idea: This is a bounding question on the strict syntactic rules of the GROUP BY SELECT list constraint.
Step 1: Recall the rule: If a query contains a GROUP BY clause, every column in the SELECT list must either be explicitly listed in the GROUP BY clause or be an argument to an aggregate function.
Step 2: Analyze the SELECT list: country and MAX(population).
Step 3: Check MAX(population): It is inside an aggregate function. This is valid.
Step 4: Check country: It is not in the GROUP BY clause (continent is), and it is not inside an aggregate function. This violates the constraint.
Step 5: Identify the correct statement. Option A correctly identifies that country is neither grouped nor aggregated.
Answer: country is in the SELECT list but is neither in the GROUP BY clause nor inside an aggregate function.
Question 4 · DatabasesMCQ
Consider the following Assertion (A) and Reason (R) regarding SQL clause evaluation:
Assertion (A): The `WHERE` clause is evaluated before the `GROUP BY` clause in the logical execution order.
Reason (R): The `WHERE` clause can contain aggregate functions like `SUM(salary)` to filter rows before grouping.
A.
Both A and R are true and R is the correct explanation of A.
B.
Both A and R are true but R is NOT the correct explanation of A.
C.
A is true but R is false.
D.
A is false but R is true.
Correct Answer:
C
Step-by-Step Solution
Key idea: This is a construction question testing the fundamental differences between the WHERE and HAVING clauses.
Step 1: Analyze Assertion (A). The logical execution order is FROM -> WHERE -> GROUP BY -> HAVING -> SELECT. Thus, WHERE is indeed evaluated before GROUP BY. A is true.
Step 2: Analyze Reason (R). The WHERE clause filters individual rows BEFORE any grouping or aggregation occurs. Therefore, it cannot contain aggregate functions like SUM(salary). Aggregate functions must be used in the HAVING clause. R is false.
Step 3: Since A is true and R is false, the correct option is "A is true but R is false".
Answer: A is true but R is false.
Question 5 · DatabasesMCQ
Which of the following statements is TRUE regarding the GROUP BY SELECT list constraint in standard SQL?
A.
A column in the SELECT list can be omitted from the GROUP BY clause if it is wrapped in an aggregate function like MAX() or SUM().
B.
The GROUP BY clause must include every column that appears in the SELECT list, even those inside aggregate functions.
C.
A column in the SELECT list can be omitted from the GROUP BY clause if it is functionally dependent on the grouped columns, regardless of the SQL dialect.
D.
Aggregate functions in the SELECT list must also be explicitly listed in the GROUP BY clause.
Correct Answer:
A
Step-by-Step Solution
Key idea: This is a bounding question on the strict syntactic rules of the GROUP BY SELECT list constraint.
Step 1: Recall the standard SQL rule: If a query contains a GROUP BY clause, every column in the SELECT list must either be explicitly listed in the GROUP BY clause or be an argument to an aggregate function.
Step 2: Evaluate Option A. It correctly states that columns wrapped in aggregate functions do not need to be in the GROUP BY clause. This is true.
Step 3: Evaluate Option B. It claims aggregates must be in GROUP BY. This is false; aggregates are excluded from the requirement.
Step 4: Evaluate Option C. It claims functional dependency allows omission regardless of dialect. Standard SQL strictly requires explicit grouping or aggregation; functional dependency is a specific extension (SQL:1999) not universally the base rule in standard exam contexts.
Step 5: Evaluate Option D. It claims aggregates must be listed in GROUP BY. This is false.
Answer: A column in the SELECT list can be omitted from the GROUP BY clause if it is wrapped in an aggregate function like MAX() or SUM().
Question 6 · DatabasesMCQ
Consider the following Assertion (A) and Reason (R) regarding SQL clause evaluation:
Assertion (A): A condition like `SUM(salary) > 100000` can be placed in the `WHERE` clause to filter rows before grouping.
Reason (R): The `WHERE` clause operates on individual rows before any aggregation or grouping takes place, so aggregate results are not yet available.
A.
Both A and R are true and R is the correct explanation of A.
B.
Both A and R are true but R is NOT the correct explanation of A.
C.
A is true but R is false.
D.
A is false but R is true.
Correct Answer:
D
Step-by-Step Solution
Key idea: This is a construction question testing the fundamental differences between the WHERE and HAVING clauses.
Step 1: Analyze Assertion (A). The WHERE clause filters individual rows BEFORE any grouping or aggregation occurs. Therefore, it cannot contain aggregate functions like SUM(salary). A is false.
Step 2: Analyze Reason (R). The WHERE clause indeed operates on individual rows before aggregation, meaning aggregate results do not exist at that stage. R is true.
Step 3: Evaluate the relationship. Since A is false and R is true, and R correctly explains why A is false (you can't use aggregates in WHERE because they don't exist yet), the correct option is "A is false but R is true".
Answer: A is false but R is true.
Question 7 · DatabasesNAT
Let R(A,B) contain exactly 20 tuples with ΠA(R) yielding exactly 6 distinct values. Let S(B) contain exactly 4 tuples. In the standard construction of division, let T1=ΠA(R)×S and T2=T1−R. Suppose T2 contains exactly 8 tuples and ΠA(T2) yields exactly 2 distinct values. The number of tuples in R÷S is __________.
Correct Answer:
4.00
Step-by-Step Solution
Key idea: this is a direct substitution into the division construction formula. The formula is R÷S=ΠX(R)−ΠX(T2), so the size is ∣ΠX(R)∣−∣ΠX(T2)∣.
Step 1 — Identify the components from the statement:
∣ΠA(R)∣=6 (given directly).
∣ΠA(T2)∣=2 (given directly).
Step 2 — Apply the formula:
∣R÷S∣=∣ΠA(R)∣−∣ΠA(T2)∣=6−2=4.
Step 3 — Sanity check: T1=ΠA(R)×S has 6×4=24 tuples. T2=T1−R has 8 tuples, meaning R contains 24−8=16 of those 24 candidate pairs. The remaining 8 missing pairs involve exactly 2 distinct A-values, so those 2 A-values are the failures. The other 6−2=4A-values have no missing pairs and survive.
Answer: 4.00.
Common trap: a student might compute 6+2=8 (adding instead of subtracting), confusing the direction of the set difference. The formula is candidates minus failures, not candidates plus failures.
Question 8 · DatabasesMCQ
A relation has 10 tuples. The attribute X has some NULL values. What is the MAXIMUM number of NULL values in X such that AVG(X) does not return NULL?
A.
8
B.
9
C.
10
D.
0
Correct Answer:
B
Step-by-Step Solution
Key idea: This is an observation question on the boundary condition for aggregate functions handling NULLs.
Step 1: Recall the rule for AVG(X). It calculates the sum of non-NULL values divided by the count of non-NULL values.
Step 2: If ALL values in the column are NULL, the count of non-NULL values is 0. Division by zero or an empty set results in NULL.
Step 3: Therefore, to get a valid numeric average, there must be at least one non-NULL value.
Step 4: With 10 total tuples, the maximum number of NULLs allowed is 10−1=9.
Answer: 9
Question 9 · DatabasesMCQ
A SQL query contains the clauses SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY. If a student assumes the database executes these clauses in the exact order they are written, how many of these clauses will actually be executed at a different position in the logical execution order?
A.
3
B.
4
C.
5
D.
6
Correct Answer:
C
Step-by-Step Solution
Key idea: This is a casework question on the logical execution order of SQL clauses compared to their written order.
Step 1: List the written order: 1:SELECT, 2:FROM, 3:WHERE, 4:GROUP BY, 5:HAVING, 6:ORDER BY.
Step 2: List the logical execution order: 1:FROM, 2:WHERE, 3:GROUP BY, 4:HAVING, 5:SELECT, 6:ORDER BY.
Step 3: Compare the positions of each clause.
SELECT: Written 1, Logical 5 (Different)
FROM: Written 2, Logical 1 (Different)
WHERE: Written 3, Logical 2 (Different)
GROUP BY: Written 4, Logical 3 (Different)
HAVING: Written 5, Logical 4 (Different)
ORDER BY: Written 6, Logical 6 (Same)
Step 4: Count the clauses with different positions. There are exactly 5 such clauses.
Answer: 5
Question 10 · DatabasesMCQ
A relation has 20 tuples. The attribute bonus contains some NULL values. What is the MAXIMUM possible difference between the results of COUNT(*) and COUNT(bonus) for this relation?
A.
0
B.
10
C.
19
D.
20
Correct Answer:
D
Step-by-Step Solution
Key idea: This is an observation question on the boundary condition of how COUNT(*) and COUNT(column) handle NULLs.
Step 1: Recall the rules. COUNT(*) counts all rows in the relation, regardless of NULLs. COUNT(bonus) counts only the rows where bonus is NOT NULL.
Step 2: To maximize the difference, we need to maximize COUNT(*) and minimize COUNT(bonus).
Step 3: COUNT(*) is fixed at 20. The minimum possible value for COUNT(bonus) is 0, which occurs when all 20 rows have a NULL in the bonus column.
Step 4: Calculate the maximum difference: 20 - 0 = 20.