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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -