php - MySQL "like" (false positive) -
i have table in database, field named "tags", e.g. ios, android, java, javascript, etc.. , want select items in table, match tag, e.g
id | name | tags
-- | ------- | -----
1 | name1 | ios,android
2 | name2 | javascript,css
3 | name3 | html,java
now, if want items have tag 'java' (only 1 id=3), this:
select * posts tags '%java%';
but, imagine, returns me second (javascript) , third (java) items..
how can return third?
in mysql, best solution find_in_set()
:
select * posts find_in_set('java', tags) > 0;
in mysql , other databases, can like
, need put delimiters around everything:
select * posts concat(',', tags, ',') '%,java,%';
the delimited prevent confusion similar tags (well, confusion doesn't involve commas).
Comments
Post a Comment