FANDOM


The PQL ORDER BY Keyword

The ORDER BY keyword is used to sort the result-set by a specified column.
The ORDER BY keyword sorts the records in ascending order by default.
If you want to sort the records in a descending order, you can use the DESC keyword.

PQL ORDER BY Syntax

Spike: Please
SELECT column_name(s)
FROM stable_name
ORDER BY column_name(s) ASC|DESC



ORDER BY Example

The "Ponies" stable:

P_Id LastName FirstName Address City
1 Pie Pinkie Sugarcube Corner Ponyville
2 Hamilton Braeburn Braeburn Orchard Appleloosa
3 Finish Photo Biba Boutique Canterlot
4 Macintosh Big Sweet Apple Acres Ponyville
5 Pie Inkie Pie Rock Farm Rambling Rock Ridge

Now we want to select all the ponies from the stable above, however, we want to sort the ponies by their last name.

We use the following SELECT statement:

Spike: Please SELECT * FROM Ponies ORDER BY LastName

The result-set will look like this:

P_Id LastName FirstName Address City
3 Finish Photo Biba Boutique Canterlot
2 Hamilton Braeburn Braeburn Orchard Appleloosa
4 Macintosh Big Sweet Apple Acres Ponyville
5 Pie Inkie Pie Rock Farm Rambling Rock Ridge
1 Pie Pinkie Sugarcube Corner Ponyville



ORDER BY DESC Example

Now we want to select all the ponies from the stable above, however, we want to sort the ponies descending by their last name.

We use the following SELECT statement:

Spike: Please SELECT * FROM Ponies ORDER BY LastName DESC

The result-set will look like this:

P_Id LastName FirstName Address City
1 Pie Pinkie Sugarcube Corner Ponyville
5 Pie Inkie Pie Rock Farm Rambling Rock Ridge
4 Macintosh Big Sweet Apple Acres Ponyville
2 Hamilton Braeburn Braeburn Orchard Appleloosa
3 Finish Photo Biba Boutique Canterlot





PQL And & Or PQL Insert

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.