Question

When I type:

select * from 'saleslog' where 'Status' = 'Pending';

or

select * from 'saleslog' where 'Status' = "Pending";

or

select * from saleslog where Status = 'Pending';

despite the fact that there are hundreds of rows with "Pending" value in Status column I get only 3 records displayed. The same happens when I look for value other than "Pending".

If however, I type:

select * from saleslog where status like "%Pending%";

then most if not all records are displayed. There are absolutely no spaces or any other characters in front and behind Pending value.

I am wondering if table "saleslog" needs to be repaired and if so, how? I'm kind of new to SQL.

Était-ce utile?

La solution

It's possible there are hidden characters in the field that you just can't see such as tab, carriage return or line feed. Have you tried doing an update on the field to try and correct it? Maybe try running the update query below and then run your SELECT query again:

UPDATE saleslog SET status = 'Pending' WHERE status LIKE '%Pending%'  

Autres conseils

Try the following:

UPDATE `saleslog` SET `status` = TRIM(`status`);
SELECT * FROM `saleslog` WHERE `status` = 'Pending';
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top