ORDER BY SQL

The ORDER BY phrase in SQL can arrange the rows based on a particular column. The data from this column can be sorted in ASCending or DESCending order. Records are sorted in ASCending order by default. The order may be either alphabetic or numeric depending on the data type. Syntax:

SELECT column(s) FROM table ORDER BY column ASC or DESC

For example we have a list of fictional characters:

fem_idnamebookauthor
1Scarlet O'HaraGone With the WindMargaret Mitchell
2Hermione GrangerHarry PotterJ.K. Rowling
3Jane PorterTarzanE.R. Burroughs

If we wished to arrange our list of fictional characters alphabetically by their first name we could do the following:

SELECT name FROM fict_chars ORDER BY name ASC

Our result:

name
Hermione Granger
Jane Porter
Scarlet O'Hara

< NULL | PREPARE and EXECUTE >


Send notes in disappearing ink!

Interesting Pages