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?
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 ).
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.
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.
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.
SELECT FIELD1, FIELD2 FROM TABLE ORDER BY FIELD1 ASC, FIELD2 ASC
A good tutorial on this SQL ORDER BY
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