我可以忽略重复记录并使用DISTINCT
或GROUP BY
获取单个值,
但是我可以完全忽略那些包含重复值的行吗?
这是我的query
SELECT DISTINCT `user_favourite_bookmarks`.`bookmark_id`
FROM `user_favourite_bookmarks`
LEFT JOIN `user_bookmarks` ON `user_favourite_bookmarks`.`bookmark_id`=`user_bookmarks`.`bookmark_id`
AND `user_bookmarks`.`user_id`=14
我得到单bookmark_id
,它有重复,我可以忽略该值吗?
答案 0 :(得分:0)
您不需要distinct
,可以使用group by
和having
SELECT user_favourite_bookmarks.bookmark_id from user_favourite_bookmarks
LEFT JOIN user_bookmarks ON user_favourite_bookmarks.bookmark_id=user_bookmarks.bookmark_id AND user_bookmarks.user_id=14
group by user_favourite_bookmarks.bookmark_id
having count(*) = 1