MySQL varchar has line break and a working LIKE-clause in PHP
I have a mysql/innoDB-table where streetnames and numbers are in the same field (varchar(255)) separated by a line break.
There are many ideas out there how to put it there, but now I need to search for matching streets+numbers with the help of PHP and don't find a solution:
I want to find the field "streetfield" with the following content:
street
number
and I know the exact values for street and number
I tried it with plain SQL like
SELECT * FROM table WHERE streetfield LIKE 'street number'
This didn't work. I found another approach, but this didn't work es well
SELECT * FROM table WHERE streetfield LIKE 'street'+CODE(10)+'number'
I tried CODE(13)
and CODE(10)+CODE(13)
, but without success. I can't use "%" because I need开发者_StackOverflow中文版 perfect matches. Any ideas?
SELECT *
FROM table
WHERE streetfield = 'street \n number'; --- the spaces are for clarity,
--- should be removed
or
SELECT *
FROM table
WHERE streetfield = CONCAT('street', CHAR(10), 'number');
Use:
CHAR(10) for \n
CHAR(13) for \r
Try:
SELECT * FROM table WHERE streetfield LIKE 'street\nnumber';
精彩评论