Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The following SQL statement selects the “firstname“ firstname and “surname“ surname of all the people from the country "Mexico"‘Mexico’, in the "people" table and then sorts by surname in ascending order DESC (default descending order by behaviour):

Code Block
languagesql
SELECT firstname, surname
FROM people
WHERE country = 'Mexico'
ORDER BY surname

...

The following SQL statement selects the “firstname“ firstname and “surname“ surname of all the people from the country "Mexico"‘Mexico’, in the "people" table and then sorts by surname in desc ASC(ascending order (- the default):

Code Block
languagesql
SELECT firstname, surname
FROM people
WHERE country = 'Mexico'
ORDER BY surname DESC

Example Ascending order (multiple columns)

The following SQL statement selects the “firstname“ firstname and “surname“ surname of all the people from the country "Mexico"‘Mexico’, in the "people" table and then sorts by surname in DESC (descending) order and then firstname in ASC (ascending order (- the default):

Code Block
languagesql
SELECT firstname, surname
FROM people
WHERE country = 'Mexico'
ORDER BY surname DESC, firstname ASC
Info

It is also possible to reference your columns numerically int he order they appear in the select statement e.g. ORDER BY 2 DESC, 1 ASC would achieve the same intended behaviour.

...