Why do we need to use query SELECT COLUMN1, COLUMN2
when we can just use SELECT *
and only show the columns we want?
And what's the difference between SELECT ALL
and SELECT
?
Why do we need to use query SELECT COLUMN1, COLUMN2
when we can just use SELECT *
and only show the columns we want?
And what's the difference between SELECT ALL
and SELECT
?
The question is, why would one use SELECT col1, col2
when you can easily just show what columns you like in the application and always use SELECT *
?
The main reasons are these:
Edit to answer the second part of the question:
Oh, and the difference between SELECT ALL and SELECT is that there is no difference.
SELECT ALL is the default behaviour of SELECT in all dialects I know of.
However, SELECT DISTINCT is different. It returns the unique values of a set, so if you run :
SELECT DISTINCT col1, col2
on a table that contains
1,2
1,2
2,2
2,3
you will get
1,2
2,2
2,3
There are a lot of questions posted before comparing differences of SELECT Col1, Col2
vs SELECT *
You can find some of them here.
Which is faster/best? SELECT * or SELECT column1, colum2, column3, etc
Is there a difference between Select * and Select
About SELECT ALL
and SELECT
:
There is no difference between these two statements and you can use SELECT Col1, Col2
or SELECT ALL Col1, Col2
If you have a look at SELECT
statement:
SELECT [ALL | DISTINCT] column1[,column2] FROM table1
ALL
is default.
If you have a big table with a lot of columns and you need only one of them "SELECT COLUMN" will be executed faster then "SELECT ALL".