指定されたタグを持つすべての user_attributes と属性を返す次のクエリがあります。
SELECT `user_attributes`.*, `attributes`.*
FROM `user_attributes`
INNER JOIN `attributes` ON (`attributes`.`id` = `user_attributes`.`attribute_id`)
INNER JOIN `user_tags` ON (`attributes`.`id` = `user_tags`.`attribute_id`)
INNER JOIN `tags` ON (`user_tags`.`tag_id` = `tags`.`id`)
WHERE `user_attributes`.`user_id` = '1'
AND `tags`.`title` IN ('tag1')
2 つのタグを持つすべての値が検索されるようにクエリを調整したいと思います。現時点で私は持っています:
SELECT `user_attributes`.*
FROM `user_attributes`
INNER JOIN `attributes` ON (`attributes`.`id` = `user_attributes`.`attribute_id`)
INNER JOIN `user_tags` ON (`attributes`.`id` = `user_tags`.`attribute_id`)
INNER JOIN `tags` ON (`user_tags`.`tag_id` = `tags`.`id`)
WHERE `user_attributes`.`user_id` = '1'
AND `tags`.`title` IN ('tag1', 'tag2')
HAVING (COUNT(DISTINCT `tags`.`title`) = 2)
GROUP BY なしで HAVING を使用しているため、壊れていますか?