What is the selection operation in DBMS?
A selection operator
Syntax
Parameters
In the syntax above:
denotes the selection operation. denotes any relational conditions. Relational conditions can be anything like . denotes the table from the database onto which the selection operation is being performed.
Example
Consider a case where we have a relation
Persons
Id | Name | Hometown | Age |
10 | Muhammad Ali | Ohio | 29 |
11 | Noah | Texas | 25 |
12 | Emma | Seattle | 20 |
13 | Arslan Ash | Lahore | 22 |
14 | Adam | Texas | 18 |
15 | Marques | California | 22 |
16 | Linus | Toronto | 22 |
The query below will return a table having only the records where the Age is equal to
The query's output from above will be as follows:
Output
Id | Name | Hometown | Age |
13 | Arslan Ash | Lahore | 22 |
15 | Marques | California | 22 |
16 | Linus | Toronto | 22 |
Multiple relational conditions
We can also have multiple relational conditions in the selection operation to get desired records. Multiple conditions join with logical operations (AND, OR). For instance:
The query above will select only those rows or records with age equal to
Output
Id | Name | Hometown | Age |
11 | Noah | Texas | 25 |
13 | Arslan Ash | Lahore | 22 |
14 | Adam | Texas | 18 |
15 | Marques | California | 22 |
16 | Linus | Toronto | 22 |
Conclusion
The selection operation in DBMS (Database Management System) allows us to retrieve specific records or rows from a relation based on certain conditions. Using logical operators such as AND and OR, we can combine multiple relational conditions to refine our selection and obtain the desired subset of data.
Free Resources