What is the difference in ‘%’ and ‘%%’, when used in mysql where clause with ‘LIKE’ ?
select * from `wp_users` u where u.user_nicename like "%lastuser%"
VS
select * from `wp_users` u where u.user_nicename like "%%lastuser%%"
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no difference between
%%and%when it comes to pattern matching in mysql.I’ve seen developers get confused over this when they try to match a literal
%and therefor write%%. This is most often because of the fact that format-strings often use a double%to indicate that you’d like it to be treated as an exact literal.MySQL documentation of
LIKELIKEWhat’s the origin of the string, and where is it going?
If the string is passed to a function such as
sprintfthe format-string rule I mentioned earlier is present, though there is no confusion in that case.The developer want it to be a single
%in the string passed to mysql, and therefor wrote%%.A few sample SELECTs using the LIKE operator