mercredi 25 février 2015

Select the last massage for each user [on hold]


Please help me with a query. I know, that my english is not even on basic level, but I try to explain. I want to write a query that selects every last massage from each user (I want to create a dialog page for my site). I want to make a page, where user can watch a last massage of every dialog, that he have. I`m using MySQL database.


My tables: users: id, name, surname; massages: id, sender - users.id link, recipient - users.id link, text, date, readed - 0 or 1;


This is what I tryed, but it doesn`t work:



SELECT users.id AS id, users.name AS name, users.surname AS surname,
massages.text AS text, massages.date AS date
FROM users, massages
WHERE massages.id IN (SELECT MAX(id)
FROM massages
WHERE (massages.recipient=uesrID AND massages.sender=users.id)
OR (massages.recipient=uesrs.id AND massages.sender=userID))


P.S. Sorry for my english.





Aucun commentaire:

Enregistrer un commentaire