O'Reilly logo

MariaDB Crash Course by Ben Forta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5. Sorting Retrieved Data

In this chapter, you learn how to use the SELECT statement’s ORDER BY clause to sort retrieved data as needed.

Sorting Data

As you learned in Chapter 4, “Retrieving Data,” the following SQL statement returns a single column from a database table. But look at the output. The data appears to be displayed in no particular order at all.

Input

SELECT prod_name FROM products;

Output

+----------------+ | prod_name      | +----------------+ | .5 ton anvil   | | 1 ton anvil    | | 2 ton anvil    | | Oil can        | | Fuses          | | Sling          | | TNT (1 stick)  | | TNT (5 sticks) | | Bird seed      | | Carrots        | | Safe           | | Detonator      | | JetPack 1000   | | JetPack 2000   | +----------------+

Actually, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required