Reputation: 155
I am trying to search for any rows that contain %20 in my database via phpmyadmin. Here's my query:
select * from `jos_picmicro_content` where `introtext` like '\%20' escape '\';
Except it returns the following error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''\'' at line 1
What have I done wrong?
Upvotes: 1
Views: 2568
Reputation: 15381
Did you try simply:
select * from jos_picmicro_content
where introtext
like '%\%20%'
Upvotes: 0
Reputation: 141887
You can remove the escape '\';
part of your query since the default MySQL escape character is '\'. But if you really need the escape
portion then you have to input it as:
escape '\\';
Or
escape '\\\\';
Upvotes: 0
Reputation:
This is probably related to MySQL's non-standard usage of the \
character. But you can specify any character with the ESCAPE
keyword:
select *
from jos_picmicro_content
where introtext like '@%20' escape '@';
But this still won't return anyhting other than rows where introtext is exactly '%20'
, you still need to use a wildcard to find %20
anywhere in that column:
select *
from jos_picmicro_content
where introtext like '%@%20%' escape '@';
Upvotes: 2
Reputation: 7504
You've escaped the '
. The correct syntax is:
select * from `jos_picmicro_content` where `introtext` like '\%20' escape '\\';
In order to identify the problem quickly, divide your query to different rows, e.g.:
select * from `jos_picmicro_content`
where `introtext`
like '\%20'
escape '\\';
Then MySQL will alert at which row the problem is.
Upvotes: 5