Can anyone explain why this query returns an empty result.
SELECT *
FROM (`bookmarks`)
JOIN `tags` ON `tags`.`bookmark_id` = `bookmarks`.`id`
WHERE `tag` = 'clean'
AND `tag` = 'simple'
In my bookmarks table, I have a bookmark with an id of 70 and in my tags table i have two tags ‘clean’ and ‘simple’ both that have the column bookmark_id as 70. I would of thought a result would have been returned?
How can I remedy this so that I have the bookmark returned when it has a tag of ‘clean’ and ‘simple’?
Thanks all for any explanation and solution to this.
Update
My tag table holds many tags. A bookmark can have many tags. id in the bookmarks table and the bookmark_id in the tags table are linked.
It’s unlikely that there’s a row whose tag equals both ‘clean’ and ‘simple’ 🙂
So try replacing AND with OR:
If you intend to retrieve only bookmarks with both tags, consider a double
existsclause:It’s also possible to check using a
havingstatement:The
countwill ensure both tags are found.