SELECT TOP

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
nmotion
Forum Commoner
Posts: 32
Joined: Wed Jan 22, 2003 6:53 am

SELECT TOP

Post by nmotion »

I'm used to code in ASP and MS SQL server. I use SQL like "SELECT TOP 10 " but in PHP the TOP code doesn't seem to work.

Is this true ?
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

The TOP command is a database dependent thing, not PHP. MySQL does not use TOP, instead it uses LIMIT.

ex1: SELECT * FROM Table LIMIT 10 // select first 10 rows
ex2: SELECT * FROM Table LIMIT 5,15 // select rows 6-20 (offset 5, limit 15)

I am unsure as to what the command is for PostGRESQL, if you are using that db. Just check the docs.
nmotion
Forum Commoner
Posts: 32
Joined: Wed Jan 22, 2003 6:53 am

It works but

Post by nmotion »

Thanks, I use MySQL and your tip works.

There is just a little but... Is it me or does this seem slow like it is looking trough a lot of rows and first at the end limit it to say 2 rows.
Post Reply