0

使用左连接我有这个结果。

这里的屏幕
http://f.cl.ly/items/373Y141r1K131d0n3f1q/Schermata%202013-04-01%20alle%2016.51.18.png

我只想显示一次记录,不重复,但是左连接我的所有记录都是不同的。
一旦我的所有记录都显示出来,我需要做什么?

查询。

 SELECT * FROM login_users
 LEFT JOIN login_users_seguaci
 ON login_users.user_id = login_users_seguaci.following
 WHERE name LIKE ""
 AND user_id != '1'
 ORDER BY data DESC
4

1 回答 1

0
SELECT  x.*, y.*
FROM    login_users x
        LEFT JOIN
        (
            SELECT  a.*
            FROM    login_users_seguaci a
                    INNER JOIN
                    (
                        SELECT  following, MAX(DATA) max_data
                        FROM    login_users_seguaci
                        GROUP   BY following
                    ) b ON  a.following = b.following AND
                            a.DATA = b.max_date
        ) y ON x.user_id = y.following
//  WHERE   ... your condition here ...
ORDER   BY t.data DESC
于 2013-04-01T15:02:39.983 回答