Q.The following query displays details of all the employees who are working either in DeptId D01, D02 or D04.
🔒You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
🔒 Start your 14-day free trial to unlock the full solution →Concept understanding — Relational Algebra Selection
Relational Algebra Selection: A First Look
Think of a railway reservation counter. The clerk has a massive register listing every train, every date, every coach, and every passenger. Now, a passenger walks in and says, "I want to see only the trains going to Delhi on 15th December." The clerk does not read out the entire register. Instead, he flips through, picks out only those rows that match "destination = Delhi" and "date = 15th December," and shows you just those.
That act of picking specific rows from a table based on a condition is exactly what Selection does in relational algebra.
The Core Idea
Selection is the operation that chooses rows from a relation (a table) that satisfy a given condition. It is like a filter — you pass a table through it, and only those rows that meet your criteria come out the other side. Everything else is discarded.
The condition you specify is called a predicate. It is a simple test that each row is checked against. For example:
- "City is 'Mumbai'"
- "Age is greater than 18"
- "Status is 'Active'"
Only rows for which the predicate is true are kept. Rows where it is false are removed.
Why It Matters
In the real world, data tables are enormous. A bank's transaction table might have millions of rows. A school's student database might have thousands. You never want to work with the entire table at once — you want only the relevant subset. Selection is how you get that subset.
The NCERT textbook (Class 12 Computer Science, Chapter on Database Concepts) introduces Selection as one of the fundamental operations of relational algebra. It states that Selection is used to retrieve tuples (rows) that satisfy a specific condition. The textbook emphasises that Selection works on a single relation and produces another relation (a subset of rows) as its result.
Key Points to Remember
- Selection reduces the number of rows, not columns. The output has the same columns as the input, but fewer rows.
- The condition can involve comparisons: equal to, not equal to, greater than, less than, greater than or equal to, less than or equal to.
- Conditions can be combined using logical operators like AND, OR, and NOT. For instance: "City = 'Delhi' AND Age > 18" selects rows that satisfy both conditions.
- The result of a Selection is itself a relation — so you can apply further operations on it.
Selection is often confused with Projection. The difference is simple: Selection picks rows (horizontal filtering), while Projection picks columns (vertical filtering). If you want only certain columns, that is Projection. If you want only certain rows, that is Selection. If you want both, you apply Selection first, then Projection.
A Simple Example (Without Numbers)
Imagine a table called Students with columns: RollNo, Name, City, and Grade.
If you want to see only those students who live in "Pune," you apply Selection with the condition "City = 'Pune'." The result is a new table that has the same four columns, but only the rows where the City column contains "Pune." …
Employees in department D01, D02, or D04.
SELECT * FROM EMPLOYEE
WHERE DeptId = 'D01' OR DeptId = 'D02' OR DeptId = 'D04';
-- equivalently: WHERE DeptId IN ('D01','D02','D04');
Output:
Employees in department D01, D02, or D04.
SELECT * FROM EMPLOYEE
WHERE DeptId = 'D01' OR DeptId = 'D02' OR DeptId = 'D04';
-- equivalently: WHERE DeptId IN ('D01','D02','D04');
Output:
- CBSE 2026Set 91/41 markMCQQ.What will be the output of the query ? SELECT MACHINE_ID, MACHINE_NAME FROM INVENTORY WHERE QUANTITY <= 100; (A) All columns of INVENTORY table with quantity greater than 100 (B) ID and name of machines with quantity less than 100 from INVENTORY table (C) All columns of INVENTORY table with quantity greater than or equal to 100 (D) ID and name of machines with quantity less than or equal to 100 from INVENTORY table.
›Reveal solutionSolution
The query will retrieve the machine ID and name for all machines in the INVENTORY table that have a quantity of 100 or less.
When we interact with a database, we often need to ask it specific questions to retrieve particular pieces of information. This is where SQL (Structured Query Language) comes in, acting as our language to communicate with the database. The query provided,
SELECT MACHINE_ID, MACHINE_NAME FROM INVENTORY WHERE QUANTITY <= 100;, is a classic example of how we specify exactly what data we want to see and under what conditions.At its heart, this query performs two fundamental operations, which in the conceptual world of Relational Algebra are known as Projection and Selection. While we use SQL keywords, understanding these underlying ideas helps clarify what the database is actually doing.
Let's break down the query piece by piece:
-
SELECT MACHINE_ID, MACHINE_NAME: This is the "Projection" part. It tells the database which columns or attributes we are interested in seeing. Imagine you have a large ledger with many columns like 'Machine ID', 'Machine Name', 'Manufacturer', 'Purchase Date', 'Quantity', 'Price', etc. ThisSELECTclause is like saying, "From all these columns, I only want to look at the 'Machine ID' and 'Machine Name' columns." All other columns will be ignored in the output. -
FROM INVENTORY: This clause is straightforward. It specifies from which table the data should be retrieved. In our example, all the information we are querying resides within theINVENTORYtable. -
WHERE QUANTITY <= 100: This is the "Selection" part. It acts as a filter, determining which rows or records from theINVENTORYtable should be included in our result. It's like saying, "Out of all the machines listed in the inventory, only show me those where the value in the 'Quantity' column is less than or equal to 100." Rows that do not satisfy this condition (i.e., those with a quantity greater than 100) will be excluded from the final output.
ImportantThe
WHEREclause is crucial for filtering data. It applies a condition to each row, and only rows that satisfy this condition are passed on to the next stage of the query processing. The comparison operator<=means "less than or equal to," which includes the value 100 itself.Combining these parts, the query instructs the database to:
- Go to the
INVENTORYtable. - Examine each machine's record.
- Keep only those records where the
QUANTITYis 100 or less. - From these filtered records, display only the
MACHINE_IDandMACHINE_NAME.
Now, let's evaluate the given options based on this understanding:
- (A) All columns of INVENTORY table with quantity greater than 100 …
-
🎓Unlock everything free for 14 days
- ✓Full step-by-step solutions
- ✓Concept-first explanations
- ✓Methods, shortcuts & mistakes
- ✓PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.