Sorting by Single Column

We wish to sort the rows of a table by the values of one column.

Ascending

We wish to sort a table in increasing order of the values of one column.

In this example, we wish to sort a table in ascending order of the values of a column col_1.

SELECT *
FROM refcon.examples.dummy_table
ORDER BY col_1;

Here is how this works:

  • We specify the name of the column we wish to sort by which here is col_1 after the ORDER BY clause.
  • ORDER BY sorts in ascending (increasing) order by default.

Descending

We wish to sort a table in descending order of the values of one column.

In this example, we wish to sort dummy_table in descending order of the values of a column col_1.

SELECT *
FROM refcon.examples.dummy_table
ORDER BY col_1 DESC;

Here is how this works:

  • We specify the name of the column we wish to sort by which here is col_1 after ORDER BY clause.
  • We add DESC keyword after ORDER BY clause to sort in descending order.
SQL
I/O