i having table column has few ids put database multi select. column example contains: 1,4,5,7,9. possible check if column contains example number 5 or not in through mysql query ?. need select people have number 5 or other listed in field , print them through php.
http://dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_find-in-set
select ... find_in_set(5, list_column) but understand search bound slow. cannot use index, , cause full table-scan (reading every row in table). table grows, query become unusably slow.
please read answer is storing delimited list in database column bad?
you can use @mikechristensen's answer more standard. trick standard sql this:
select * tablename ',' || ids || ',' '%,5,%' (in standard sql, || string concatenation operator, in mysql, have set sql_mode=pipes_as_concat or set sql_mode=ansi behavior.)
another mysql-specific solution use special word-boundary regular expression, match either comma punctuation or beginning/end of string:
select * tablename ids rlike '[[:<:]]5[[:>:]]' none of these solutions scale well; cause table-scans. sorry understand cannot change database design, if project next requires make query faster, can tell them it's not possible without redesigning table.
Comments
Post a Comment