如何忽略MySQL中的重复行?

时间:2015-02-16 07:37:38

标签: mysql

我可以忽略重复记录并使用DISTINCTGROUP 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,它有重复,我可以忽略该值吗?

1 个答案:

答案 0 :(得分:0)

您不需要distinct,可以使用group byhaving

来完成
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