-1

このクエリがあり、結果が double であるため、DISTINCT に変換する必要があります。どうすればよいですか?

SELECT x.id_msg, x.id_group, x.profile_id, b.id_group, u.name, u.sirname, u.picup, u.profile_id AS profile_id_users, mp.msg_id,mp.msg_text, mp.occured_at
FROM message_view x
INNER JOIN (

SELECT a.id_msg, a.id_group, a.profile_id
FROM message_view a
WHERE a.profile_id =  'sN07X2'
)b ON x.id_group = b.id_group
INNER JOIN users u ON u.profile_id = x.profile_id
INNER JOIN message_private mp ON mp.msg_id = x.id_msg
4

1 に答える 1

1

追加

GROUP BY x.id_msg

それid_msgがPKだとします。

更新: すべての行を取得し、1 つの統計をマークするには profile_id = 'sN07X2':

SELECT 
    x.id_msg, 
    x.id_group, 
    x.profile_id, 
    IF(x.profile_id = 'sN07X2','is profile sN07X2','is not profile sN07X2'), 
    u.name, 
    u.sirname, 
    u.picup, 
    u.profile_id AS profile_id_users, 
    mp.msg_id,
    mp.msg_text, 
    mp.occured_at
FROM message_view x
LEFT JOIN users u 
    ON u.profile_id = x.profile_id
INNER JOIN message_private mp 
    ON mp.msg_id = x.id_msg
GROUP BY
    x.id_msg
于 2013-07-01T08:43:08.857 に答える