Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax for projection in SQL

What is the difference, in terms of syntax, between selection (SELECT) and projection in SQL? I know that the first isolates rows and the second columns, but I don't know how to actually get a new table with the specified columns. What is the syntax for a projection?

like image 432
mar tin Avatar asked Oct 17 '25 19:10

mar tin


2 Answers

The projection corresponds to the columns you select, the selection to the filter you define in your where clause:

SELECT ID, NAME
FROM PRODUCTS
WHERE PRICE > 100;

Here the projection corresponds to the ID and NAME columns whereas the selection corresponds to the price filter

like image 163
vc 74 Avatar answered Oct 20 '25 08:10

vc 74


Projection, according to this Article 'is selecting the name of the columns of table(s) which one wishes to see appearing in the answer'.

Example (removed a previous example that may have been confusing)

SELECT Col1, Col2 FROM [Table1]

Selection, uses WHERE Clauses to reduce the resultset and doesnt say anything about filtering columns.

SELECT * FROM [Table1] WHERE [Col1] = 'Result'

In SQL,these can be used in combination, ie. WHERE Clause and with filtering Columns;

SELECT Col1, Col2 FROM [Table1] WHERE [Col1] = 'Result'

Regards,

like image 44
ChallengeAccepted Avatar answered Oct 20 '25 08:10

ChallengeAccepted



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!