I am coding a messaging system, I am trying to select the last 10 messages sent in ascending order (Newest on the bottom).
However having an issue in doing this 🙁
This is my current SELECT statement there are over 30 rows in the table that will are available.
SELECT * FROM
( SELECT * FROM messages ORDER BY addedDate DESC LIMIT 10 ) tb
WHERE ( senderID = "1" OR receiverID = "1" )
AND ( senderID = "3" OR receiverID = "3" )
ORDER BY addedDate ASC LIMIT 10
However for some reason this only returns 7 rows, when using a different combination of sender and receiver if there are less rows than i get less than 7 results even though each should give me at least the 10 rows i want.
Is there another method I can use to get the bottom 10 rows that will match:
WHERE ( senderID = "1" OR receiverID = "1" )
AND ( senderID = "3" OR receiverID = "3" )
but select the bottom 10 in ascending order.
You should have the WHERE statement in your subquery, not your main query.
Try this:
And you don’t need that second LIMIT, as you only get 10 results from the subquery.