I need to add a join to the following query that will join the messages_message table to the messages_threads table and return the ‘body’ and ‘time’ fields from the most recent row in messages_messages where messages_message.threadid = messages_threads.id.
Sorry that’s so confusing, I don’t know how else to phrase it! Here’s my current query – which pulls everything correctly except the ‘body’ and ‘time’ fields.
SELECT
messages_threads.id AS threadid, messages_threads.name AS recipientsname,
senderid, username AS sendername, pictures.url AS senderpicture
FROM
messages_recipients
JOIN messages_threads
ON messages_threads.id = messages_recipients.threadid
JOIN users
ON users.id = messages_threads.senderid
JOIN pictures
ON messages_threads.senderid = pictures.userid
AND pictures.profile = 1
WHERE messages_recipients.userid = $userid
You could add a subquery of the messages_message table which would return 1 row for every thread. For example: