What are projection and selection?
Asked Answered
C

4

137

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?

Cam answered 23/6, 2009 at 7:25 Comment(0)
A
249

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.

Alternately answered 23/6, 2009 at 7:31 Comment(4)
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.Dirty
@Dirty Well observed, but don't put the blame on me ;-)Alternately
@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.Dirty
@Dirty this is exactly the way how I remember it. Counterintuitive.Gussy
C
17

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

Cincinnati answered 21/2, 2017 at 21:34 Comment(0)
K
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:

Kenyatta answered 8/12, 2017 at 0:50 Comment(2)
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.Saransarangi
Remeber that a tablem is the quivalent of a "relation" in rel. algabra. A record is called "tuple", a field is "attribute" of a tuple and a database is called "schema".Gussy
S
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

Septima answered 24/4, 2011 at 14:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.