$result = mysql_query("SELECT * FROM berichten where ontvanger = '$session->username'
GROUP BY fromm ORDER BY date DESC");
while($row = mysql_fetch_array($result))
{
echo $row['fromm'];
echo $row['msg'];
echo $Row['date'];
}
我想将表格从atm分组,当我这样做时,我想显示表格中的最新帖子,但显示旧帖子
答案 0 :(得分:0)
SELECT a.*
FROM berichten a
INNER JOIN
(
SELECT fromm, MAX(Date) Date
FROM berichten
GROUP BY fromm
) b ON a.fromm = b.fromm AND
a.date = b.date
WHERE a.ontvanger = '$session->username'
也可以写成
SELECT a.*
FROM berichten a
WHERE a.Date =
(
SELECT MAX(Date)
FROM berichten b
WHERE a.fromm = b.fromm
) AND
a.ontvanger = '$session->username'