I'm pretty new to SQL, so I'll try to keep it simple as to what I'm trying to do.
I have a system which I'm looking to select messages from, starting with the most recent first, select a maximum of 5 pieces of data, then after that resort them with the latest 'time' column last in order for them to display properly.
Here's the syntax I'm using:
SELECT * FROM messages WHERE sender = '$uid' AND reciever = '$new_user_id'
OR reciever = '$uid' AND sender = '$new_user_id' ORDER BY id ASC
FROM (SELECT * FROM messages ORDER BY time DESC)
And here's the error that I'm getting:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM (SELECT * FROM messages ORDER BY time DESC)' at line 1
I understand that I'm getting something wrong here, but as SQL isn't really my thing, I haven't a clue where to turn.
A little help would go to great causes, I've been banging my head on the wall for hours.
Thanks.
FROMtwice?FROMstatements. Try to break the query into sub-parts(as I have done in my answer) it helps you know the logic better. ;)