I have a query like this:
SELECT message_text
FROM messages
WHERE message_date >= '$connection_time'
Simple enough.
This allows me to retrieve messages being posted since the connection time.
But I also need to retrieve the last 15 messages posted before that connection time.
(The best would be to do this all with a single query).
How would I do that?
PS: I thought about getting the id of the first message retrieved and subtract 15 of it but it only works if the id’s are consecutive which is not always the case.
Thank you.
Join the following query to your existing one with
UNION:By the way, I really really really hope that you’re absolutely certain
$connection_timehas been stripped of any potential SQL injection attacks (if you don’t know what that means, go and read about Bobby Tables). You ought to use prepared statements, into which you pass your variables as parameters that do not get evaluated for SQL.