This topic is locked

Limit records

8/27/2007 11:54:20 AM
PHPRunner General questions
M
mmponline author

I need a SQL query that will only show the last (maost recent) 5 records entered. It can thus be the last 5 Auto Increment Numbers (Largest 5) or the last 5 records by date inserted (I have a date field)
What would be the easiest way to achieve it?

F
frocco 8/27/2007

You can try:
SELECT *

FROM

table_name

order by your_date desc

limit 5
HTH
Frank

I need a SQL query that will only show the last (maost recent) 5 records entered. It can thus be the last 5 Auto Increment Numbers (Largest 5) or the last 5 records by date inserted (I have a date field)

What would be the easiest way to achieve it?

M
mmponline author 8/27/2007

I use this query:

select `NewsID`,

`LogID`,

`Title`,

`Description`,

`Download`,

`Category`,

`Hyperlink`,

`Date`

From `_News`

order by Date desc limit 5


but get a syntax error message

Alexey admin 8/29/2007

Stephan,
PHPRunner doesn't support LIMIT clause because it adds it itself.
Create a view in your database using CREATE VIEW statement then use this view in PHPRunner.
I.e.

CREATE VIEW Last5News as

select `NewsID`,

`LogID`,

`Title`,

`Description`,

`Download`,

`Category`,

`Hyperlink`,

`Date`

From `_News`

order by Date desc limit 5

M
mmponline author 8/29/2007

Sergey
I found that I can set the show records per page on the sql page for this purpose as well - and then just remove the pagination to keep only the 5 records. This way the last 5 records is shown. Thank you for this in any way. I'm sure it would come in handy sometime.
Stephan