Query is a question or requesting information. Query language is a language which is used to retrieve information from a database.
Query language is divided into two types −
Information is retrieved from the database by specifying the sequence of operations to be performed.
For Example − Relational algebra.
Structure Query language (SQL) is based on relational algebra.
Relational algebra consists of a set of operations that take one or two relations as an input and produces a new relation as output.
The different types of relational algebra operations are as follows −
Cartesian product operation
Select, project, rename comes under unary operation (operate on one table).
It displays the specific column of a table. It is denoted by pie (∏). It is a vertical subset of the original relation. It eliminates duplicate tuples.
The syntax is as follows −
Consider the student table:
To display regno column of student table, we can use the following command −
To display branch, section column of student table, use the following command −
The result is as follows −
To display regno, section of ECE students, use the following command −
Note: Conditions can be written in select operation but not in projection operation.
Consider the employee table to know more about projection.
If no condition is specified in the query then, Π empid, ename, salary, address, dno (emp).
If condition is specified then, the composition of the select and projection is as follows −
∏ empid, ename, salary, address, dno (σ salary >20,00 ^ LOC = HOD ^ dno=20) (emp)