开发者

Add a chracter to data in MySQL column temporarily for a select query

开发者 https://www.devze.com 2023-02-07 06:19 出处:网络
is there anyway to add a 开发者_运维技巧character to every row in the column in 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号