FANDOM



The PQL TOP Clause

The TOP clause is used to specify the number of records to return.
The TOP clause can be very useful on large stables with thousands of records.
Returning a large number of records can impact on performance.
Note: Not all database systems support the TOP clause.

PQL Server Syntax

Spike: Please
SELECT TOP NUMBER|percent column_name(s)
FROM stable_name



PQL SELECT TOP Equivalent in MyLittlePQL and MadamePinky

MyLittlePQL Syntax

Spike: Please
SELECT column_name(s)
FROM stable_name
LIMIT NUMBER

Example

Spike: Please SELECT * FROM Ponies LIMIT 5



MadamePinky Syntax

Spike: Please 
SELECT column_name(s)
FROM stable_name
WHERE ROWNUM <= NUMBER

Example

Spike: Please SELECT * FROM Ponies WHERE ROWNUM <=5



PQL TOP 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

Now we want to select only the two first records in the stable above.

We use the following SELECT statement:

Spike: Please SELECT TOP 2 * FROM Ponies

The result-set will look like this:

P_Id LastName FirstName Address City
1 Pie Pinkie Sugarcube Corner Ponyville
2 Hamilton Braeburn Braeburn Orchard Appleloosa



PQL TOP PERCENT 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

Now we want to select only 50% of the records in the stable above.

We use the following SELECT statement:

Spike: Please SELECT TOP 50 PERCENT * FROM Ponies

The result-set will look like this:

P_Id LastName FirstName Address City
1 Pie Pinkie Sugarcube Corner Ponyville
2 Hamilton Braeburn Braeburn Orchard Appleloosa



PQL Delete PQL Like

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.