This should be so simple, but I'm drawing a blank. I have two tables.
Table:article_tag_pvt
colum: article_id
column: tag_id
Table: tag
column: tag_id
column: name
The article_tag_pvt
table is a many-to-many pivot table.
The problem is, I need a query which given a list of tag names, will retrieves article Ids which ONLY match those tag names. The basic joining of these tables looks like this:
SELECT article_id
FROM article_tag_pvt pvt
INNER JOIN tag t ON t.tag_id = pvt.tag_id
I've already got a query which will retrieve article ids which match ANY tag names specified. This looks like this:
SELECT article_id
FROM article_tag_pvt pvt
INNER JOIN tag t ON t.tag_id = pvt.tag_id
WHERE t.name IN ('events','news')
I've tried these but no joy:
SELECT article_id
FROM article_tag_pvt pvt
INNER JOIN tag t ON t.tag_id = pvt.tag_id
WHERE t.name = 'events' AND t.name = 'news'
SELECT article_id
FROM article_tag_pvt pvt
INNER JOIN (
SELECT tag_id
FROM tag
WHERE name IN ('events','news')
) AS t
ON t.tag_id = pvt.tag_id
Any help would be greatly appreciated
Dave