Imagine we have following table
create table t
(item number,
bin number,
primary key (bin , item) );
I have used insert into command to insert several values into table t
, now i am interested in what does this code
select * from t
order by 1,2;
As far as i know it selects everything from table t
and sorts it, because order means to sort selected query using condition listed in order command, but order 1,2
i could not understand what does it means, could you help me ?
It will order the results by the first column, and then, if there are some rows with the same value in the first column it will order them by the second column.
it simply means sorting the view or table by 1st column of the query's result.
SELECT first_name, last_name FROM sales.customers ORDER BY 1, 2; In this example, 1 means the first_name column, and 2 means the last_name column. Using the ordinal positions of columns in the ORDER BY clause is considered a bad programming practice for a couple of reasons.
It means to group by the first column of your result set regardless of what it's called. You can do the same with ORDER BY .
It sorts the result by the first and second column, so in your case it's identical to
select *
from t
order by item, bin;
select * from t
order by item, bin; // just different written but result is same.
Result
will be sorted by first and second column.
Difference is in readability of code so if someone don't know information about table, your select
says nothing him. Person only knows that result will be sorted by 1. and 2. column, nothing more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With