【发布时间】:2014-05-01 10:33:42
【问题描述】:
SELECT DISTINCT msg.userid, msg.messages, user.fullname, prof.path
FROM messages AS msg
LEFT JOIN users AS user ON msg.userid = md5( user.userid )
LEFT JOIN profile AS prof ON msg.userid = prof.userid
ORDER BY msg.date ASC
LIMIT 0 , 30
上面的代码可以运行,但问题是结果有重复值:
userid | messages | fullname | path
985434 | hello... | Foo Bar | /path/to/hello.jpg
985434 | hello... | Foo Bar | /path/to/new.jpg
问题是PATH。 如何将path 的结果限制为最新的?还是每个全名只有一个?...这让我很生气感谢您的理解。
【问题讨论】:
-
按 msg.userid 使用组
-
是的..有没有办法将左连接限制为 1...我尝试了子查询并将 LIMIT 0,1 ..问题是除了第一个路径之外的所有其他路径成为
null
标签: mysql sql left-join greatest-n-per-group