Page 1 of 1

mysql like syntax with backslash

Posted: Thu Mar 04, 2010 4:38 pm
by thomas
Hi,

I have a database table name "test" with one field name "fname" and in that table I have an entry "abc\123". I tried running the queries below and got no result.

select * from test where fname like '%abc\123%'
or
select * from test where fname like '%abc\\123%'

I'm not sure if the mysql like syntax have any problem with backslashes but is there a way to get around this?

Re: mysql like syntax with backslash

Posted: Thu Mar 04, 2010 6:49 pm
by mikosiko
thomas wrote:Hi,

I have a database table name "test" with one field name "fname" and in that table I have an entry "abc\123". I tried running the queries below and got no result.

select * from test where fname like '%abc\123%'
or
select * from test where fname like '%abc\\123%'

I'm not sure if the mysql like syntax have any problem with backslashes but is there a way to get around this?
select * from test where fname like '%abc%'

or
select * from test where fname like '%abc%123%'
could do the job... but also can give you unwanted records... per example this records will be returned also:
fname="abcjsd jsd j jsd jhs"
faname="abc shdjhjashd 123 hsdhjashd"

and this
select * from test where fname like '%abc_123%'
should solve your pattern