Search in Tags Set in MySQL

Submitted by:Andery Smith

Date added:23 November, 2013

Category:MySQL

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.

Tags: search tags , set tags

Code Snippet:

    -- 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;
 
 

Comments