scriptkiddie scriptkiddie - 1 year ago 55
MySQL Question

mysql error: Llike operator throws error

I dont know what is the problem in my query but it throws some error.

select * from tbl_emailswipes where
eswipes_title like '% 1939 %',
or eswipes_title like '% 1939%',
or eswipes_title like '%1939 %',
or eswipes_title like '%1939%',
or eswipes_text like '% 1939 %',
or eswipes_text like '% 1939%',
or eswipes_text like '%1939 %',
or eswipes_text like '%1939%'

and the error is

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '

or eswipes_title like '% 1939%',
or eswipes_title like '%' at line 2

Please help solve this issue

Answer Source

No commas are needed. But, this would be much more easily written as:

select es.*
from tbl_emailswipes es
where concat(' ', es.eswipes_title, ' ') like '% 1939 %' or
      concat(' ', es.eswipes_text, ' ') like '% 1939 %';

The logic in this query simplifies the comparisons. It adds a separator (' ') at the beginning and end of the columns. This makes it much easier to find a word in the pattern.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download