join - MySQL - get elements from a link table but ONLY those elements -
There is a problem with selecting a link from the table and filtering out more than enough results.
Publication relates to Package via the Package_Publication table. For example, I know of my publications being ID 11 and 47. I want to return a package which is only in those publications.
Now if I join one and do something like then publication.id IN (11, 47)
after the obvious internal joins, it only returns all those packages Which will be one of those values in the package_publications link table.
I want to match those packages in which only both (or more - it is not limited to two). Effectively I want one or the other when I am using, but I do not know how to contact it with SQL-wise.
Your best bet is a correlated subquery. The second option is associated with different groups but it Not performing well, especially on the big table.
Subkey:
SELECT * `packages` WHERE 2 = (`number of selects (*) from` package_publications` where`` package_. id = `package_publications`.package_id And `package_public publication`. Publication_id IN (11, 47))
Comments
Post a Comment