如果没有任何唯一约束,请尝试:
SELECt post_id FROM tags WHERe tag_id = 1 OR tag_id = 3 GROUP BY post_id HAVINg count(DISTINCT tag_id) = 2;
HAVINg如果仅尝试检测两个
tag_id值,请使用此子句:
HAVINg MIN(tag_id) <> MAX(tag_id)
如果post_id和tag_id都具有唯一约束,那么这也应该起作用:
SELECt post_id FROM tags WHERe tag_id = 1 OR tag_id = 3 GROUP BY post_id HAVINg count(*) = 2;



