mardi 24 février 2015

selects every last massage from each user


Help me, please, with one query. I need a querry, that selects every last massage from each user (I wants to create dialogs page for my site).


My tables:


users: id, name, surname; massages id, sender,recipient, text, date


Its my try, but it dont works...



SELECT users.id AS id, users.name AS name, users.surname AS surname,
massages.textAS 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 engliish)))





Aucun commentaire:

Enregistrer un commentaire