0
SELECT SUBSTRING(m.content,1,20) as content, 
       m.viewed, m.sent_date, 
       u.username 
FROM message m 
INNER JOIN user u 
ON u.userid = m.message_from
WHERE m.message_to = :userid

我对这个查询的问题是它从同一个用户名中选择了多行。我只希望它为每个用户名选择一行。

我相信我为此使用了 DISTINCT?

我无法让它工作,有人可以帮助我!

谢谢。

4

2 回答 2

1
SELECT SUBSTRING(m.content,1,20) as content, m.viewed, m.sent_date, u.username 
FROM message m INNER JOIN user u ON u.userid = m.message_from
WHERE m.message_to = :userid GROUP BY u.userid
于 2013-03-31T17:39:41.053 回答
-1

是的!你可以在你的用户名中使用 distinct

SELECT Distinct( u.username ), SUBSTRING(m.content,1,20) as content, 
       m.viewed, m.sent_date           
FROM message m 
INNER JOIN user u 
ON u.userid = m.message_from
WHERE m.message_to = :userid
于 2013-03-31T17:53:47.387 回答