Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to perform ORDER by Twice

I want to sort according to date first and then if date is similar then according to id..How to do that in Informix/HSQL query?

like image 472
coderslay Avatar asked Dec 16 '11 10:12

coderslay


People also ask

Can we use ORDER BY 2 times in SQL?

After the ORDER BY keyword, add the name of the column by which you'd like to sort records first (in our example, salary). Then, after a comma, add the second column (in our example, last_name ).

Can we use ORDER BY for 2 columns?

If you want to select records from a table but would like to see them sorted according to two columns, you can do so with ORDER BY. This clause comes at the end of your SQL query.

Can we have multiple ORDER BY?

SQL ORDER BY Multiple Columns However we can use multiple columns in ORDER BY clause. When multiple columns are used in ORDER BY, first the rows will be sorted based on the first column and then by the second column.

What is ORDER BY 2 in SQL?

Sort by ordinal positions of columns But instead of specifying the column names explicitly, it uses the ordinal positions of the columns: 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.


1 Answers

SELECT FIELD1, FIELD2 FROM TABLE ORDER BY FIELD1 ASC, FIELD2 ASC

A good tutorial on this SQL ORDER BY

like image 65
ChrisBint Avatar answered Sep 21 '22 12:09

ChrisBint