mysql select not woking for varchar field

11,891

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%' 
Share:
11,891
dev21
Author by

dev21

Updated on June 04, 2022

Comments

  • dev21
    dev21 almost 2 years

    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.

  • dev21
    dev21 over 10 years
    lenght(email) returning length 2 more than the actual length of email stored in database for the emails which I not able to search using SELECT statement.
  • black
    black over 10 years
    use trim function to trim the "some email" from your php code.like i said in your db the mysql is looking for "some email" but you have blank space inserted in your db for that name,which you mentioned that length function is returning 2more values, that means you have blank space ther alongwith the name. use $someemail= (trim($_POST['some email'])) when capturing from the form . it will solve the issue