mysql select not woking for varchar field

2019-06-08 20:19发布

问题:

I have table with email field of type varchar.

select * 
from `table_name` 
WHERE email='some email'

working well for all the other email except one email in the table.

回答1:

When this works for your problematic record

select * from table_name 
where email like '%some email%' 

Then you have leading or trailing spaces in your data.

To revert that update your existing table data like this

update table_name
set email = trim(email)
where email like '%some email%' 


回答2:

may be you have blankspace in your email. you can check the length of the email.

SELECT length(email) 
FROM  `table_name`
WHERE  `email` LIKE  '%email%'

use wildcard

select * from table_name 
where email like '%some email%' 

or visit here for more combination http://www.w3schools.com/sql/sql_wildcards.asp