131

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?

dreftymac
  • 31,404
  • 26
  • 119
  • 182

4 Answers4

237

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.

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
Erich Kitzmueller
  • 36,381
  • 5
  • 80
  • 102
  • 11
    Indeed a clear explanation, but I find this aspect of SQL confusing/misleading: the `SELECT` clause actually performs a *projection* (not selection), and it's the `WHERE` clause that actually performs a *selection*. – flow2k Feb 18 '20 at 04:46
  • 9
    @flow2k Well observed, but don't put the blame on me ;-) – Erich Kitzmueller Feb 18 '20 at 15:38
  • 2
    @ErichKitzmueller Ha - rest assured I had no such intention; sometimes I find coming to terms/accepting these subtle points of a definition, or syntax, makes me remember it better. – flow2k Feb 21 '20 at 05:44
15

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

12

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:

Arnab
  • 1,308
  • 1
  • 13
  • 18
  • This actually helped in making the terms make sense. Selection is choosing a subset of the set of rows. And if you think of N-column values being a point in N-dimensional space, projecting (orthogonally) down to only K-dimensions eliminates some of the column values resulting in K-component tuples for each row. – karmakaze Dec 23 '21 at 00:44
9

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

suspectus
  • 16,548
  • 8
  • 49
  • 57
AlluriReddy
  • 117
  • 1
  • 1