Problems with <> via an INNER JOIN query in MySQL -
i'm trying find tag name, if reference doesn't exist in relationship table:
select tags.tag_id, tags.tag tags inner join bookmarks_tags on (bookmarks_tags.user_id = tags.user_id) (tags.user_id = '1') , (tags.tag '%jose%') , (bookmarks_tags.tag_id not in (tags.tag_id)) group tags.tag_id
i've tried combinations of "!=", "<>", , above, in every permutation can think of, none exclude "jose", should given tag present in "tags" table, , "bookmarks-tags" table, contains reference.
any ideas?
do left join , exclude rows match:
select tags.tag_id, tags.tag tags left join bookmarks_tags on bookmarks_tags.user_id = tags.user_id , bookmarks_tags.tag_id = tags.tag_id tags.user_id = 1 , tags.tag '%jose%' , bookmarks_tags.tag_id null
alternatively use subquery:
select tag_id, tag tags user_id = 1 , tag '%jose%' , tag_id null , tag_id not in (select tag_id bookmarks_tags user_id = 1)
i prefer first option.
Comments
Post a Comment