mysql - select with a multiple row in pivot table -
i don't know how retrieve specific row pivot table.
here's pivot table:
+----+-------------+--------+ | id | peticion_id | tag_id | +----+-------------+--------+ | 1 | 3 | 15 | | 2 | 3 | 21 | | 3 | 3 | 28 | | 4 | 8 | 21 | | 5 | 8 | 28 | | 6 | 44 | 21 | | 7 | 44 | 28 | +----+-------------+--------+
i wanna make maybe think dynamic query example if do:
select peticion_id tag_id in (21,28,15);
the result is:
+-----+-------------+--------+ | id | peticion_id | tag_id | +-----+-------------+--------+ | 1 | 3 | 15 | | 2 | 3 | 21 | | 6 | 44 | 21 | | 4 | 8 | 21 | | 3 | 3 | 28 | | 7 | 44 | 28 | | 5 | 8 | 28 | +-----+-------------+--------+
i need result peticion_id = 3.
i don't know how formulate query, maybe i'm looking equivalent for(where in) , clause.
hope helps. thanx
try this:
select peticion_id tbl tag_id in (21,28,15) group peticion_id having count(*) = 3
Comments
Post a Comment