Mysql 有用户表、标签表,如何查询同时拥有某几个标签的用户?

哆啦的时光机
浏览 1180回答 3
3回答

守候你守候我

你那个查询的条件明显就不对// tags表 `tags`.`title` = '聪明' AND `tags`.`title` = '勤奋' 这种数据根本就不存在SELECT * FROM userWHERE id IN (    SELECT uid FROM tags WHERE title IN ('聪明', '勤奋') GROUP BY uid HAVING count(uid) = 2);

青春有我

select user.*,count(tags.uid)as num  from user left join tags on `user`.id = tags.uid where (`tags`.`title` = '聪明' OR `tags`.`title` = '勤奋') group by tags.uid having count(tags.uid) > 1 
打开App,查看更多内容
随时随地看视频慕课网APP