What are projection and selection?

SqlDatabaseRelational Algebra

Sql Problem Overview


What is the difference between projection and selection? Is it:

  • Projection --> for selecting the columns of table; and
  • Selection ---> to select the rows of table?

So are projection and selection vertical and horizontal slicing respectively?

Sql Solutions


Solution 1 - Sql

Exactly.

Projection means choosing which columns (or expressions) the query shall return.

Selection means which rows are to be returned.

if the query is

select a, b, c from foobar where x=3;

then "a, b, c" is the projection part, "where x=3" the selection part.

Solution 2 - Sql

Simply PROJECTION deals with elimination or selection of columns, while SELECTION deals with elimination or selection of rows.

Solution 3 - Sql

Projections and Selections are two unary operations in Relational Algebra and has practical applications in RDBMS (relational database management systems).

In practical sense, yes Projection means selecting specific columns (attributes) from a table and Selection means filtering rows (tuples). Also, for a conventional table, Projection and Selection can be termed as vertical and horizontal slicing or filtering.

Wikipedia provides more formal definitions of these with examples and they can be good for further reading on relational algebra:

Solution 4 - Sql

Projection: what ever typed in select clause i.e, 'column list' or '*' or 'expressions' that becomes under projection.

**selection:**what type of conditions we are applying on that columns i.e, getting the records that comes under selection.

For example:

  SELECT empno,ename,dno,job from Emp 
     WHERE job='CLERK'; 

in the above query the columns "empno,ename,dno,job" those comes under projection, "where job='clerk'" comes under selection

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionprabhaharView Question on Stackoverflow
Solution 1 - SqlErich KitzmuellerView Answer on Stackoverflow
Solution 2 - SqlHarimohan PandeyView Answer on Stackoverflow
Solution 3 - SqlArnabView Answer on Stackoverflow
Solution 4 - SqlAlluriReddyView Answer on Stackoverflow