order by date desc limit to 1 and have it grouped by
Posted: Mon Apr 01, 2013 1:12 am
This is the mysql query:
I want to get one row in which there is a unique id field, or id2 field in which either one of the two is the logged in user $uid. Ordered by datetimep
Table structure with rows in it:

What I am after is the last conversation in between the logged in user and any other user. Last row which holds in the longtext the conversation and it's timestamp and whether the sender was the logged in user or the other party, etc.
Code: Select all
$r=mysql_query("
(
SELECT *
FROM commentsvv AS dt
WHERE FIND_IN_SET(id,'$dset')>0
AND id2='$uid'
AND status_id2='0'
ORDER BY datetimep DESC LIMIT 1)
UNION
(
SELECT *
FROM commentsvv AS dt
WHERE FIND_IN_SET(id2,'$dsetv')>0
AND id='$uid'
AND status_id='0'
ORDER BY datetimep DESC LIMIT 1)
");Table structure with rows in it:

What I am after is the last conversation in between the logged in user and any other user. Last row which holds in the longtext the conversation and it's timestamp and whether the sender was the logged in user or the other party, etc.