0
SELECT blabla
FROM a INNER JOIN b ON a.a = b.b

Is what I have. However I'd like to sort the results DESC by ID. I'd like to select last [variable x 10] of items sorted by ID DESC. Variable provided by PHP (I'll sort things out, I just need help with the query itself).

Edited by Aeonix

3
Contributors
3
Replies
23
Views
1 Year
Discussion Span
Last Post by hielo
1
SELECT blabla
FROM a INNER JOIN b ON a.a = b.b
ORDER BY a.id DESC LIMIT 10;

If you're creating the SQL statement in code just replace the 10 with whatever the result of (variable x 10) is.

0

Here's the problem DESC LIMIT (variable x 10) in case of 5 it would be DESC LIMIT 50. It will give last 50 results, I need 10 results after these 50.

Something like DESC LIMIT from (variable x 10) to (variable x 10 + 10)

1

You need ... LIMIT offset, rowCount -- ex:

SELECT blabla
FROM a INNER JOIN b ON a.a = b.b
ORDER BY a.id DESC LIMIT 50, 10

will give you at most 10 rows, starting with row 50.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.