Skip to content

Instantly share code, notes, and snippets.

@apphp-snippets
Created August 14, 2013 09:33
Show Gist options
  • Save apphp-snippets/6229404 to your computer and use it in GitHub Desktop.
Save apphp-snippets/6229404 to your computer and use it in GitHub Desktop.
Lets say you have a table with field called "tags" that consists from tags separated by commas and you want to check whether it includes a required tag. Here the simplest ways of doing that.
-- source: http://www.apphp.com/index.php?snippet=mysql-search-in-tags-set#null
-- 1st way
SELECT *
FROM TABLE
WHERE FIND_IN_SET(" '.$tag.'", CONCAT(" ", TABLE.tags))
LIMIT 1;
-- 2st way
SELECT *
FROM TABLE
WHERE '.$tag.' IN(TABLE.tags)
LIMIT 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment