Add a chracter to data in MySQL column temporarily for a select query
is there anyway to add a 开发者_运维技巧character to every row in the column in a select query?
For example something like:
"SELECT * FROM table where data+' ' LIKE '%value %'"
Notice the +' '
, which is what I am trying to add, basically I want it to add a space to the end of the data value so when it searches using LIKE
it will recognize the space at the end.
is called concat
where concat(data, ' ') like '%value %'; <-- adding space at back
where concat(' ', data) like '%value %'; <-- adding space in-front
where concat(' ', data, ' ') like '%value %'; <-- adding space in-front, back
details : http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat
alternatively, you can do this instead
where data like concat('%', rtrim(value), '%');
this is to rtrim
the space of value to search
note: with space or without space might affect the match results
精彩评论