i'm trying set of values pivot table column equal array of values, example id 12 has attribute_value_id equal 3 , 9. can done? i've got far...
id | post_id | attribute_id | attribute_value_id 8 12 1 3 9 12 2 13 10 13 1 3 11 13 2 9 12 16 1 3 13 16 2 9 88 11 1 1 89 11 2 8 90 11 3 18 91 11 4 22 the query...
select * `searching_for_posts` ( select count(*) `attributes` inner join `searching_for_attributes` on `attributes`.`id` = `searching_for_attributes`.`attribute_id` `searching_for_attributes`.`searching_for_post_id` = `searching_for_posts`.`id` , (`attribute_value_id` = 3 , `attribute_value_id` = 9) ) >= 1 if use and no values. if use or 3 values should return 2. have limited sql experience.
you can using group by , having. logic hard follow, this:
select post_id table t attribute_value_id in (3, 9) group post_id having count(distinct attribute_id) = 2; i think want check on attribute_id well, doesn't seem part of question.
edit:
if these stored in table:
select a.post_id attributes join searching_for_attributes sfa on a.attribute_id = sfa.attribute_id , a.attribute_value_id = sfa.attribute_value_id group a.post_id having count(*) = (select count(*) searching_for_attributes);
Comments
Post a Comment