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.

Was it helpful?

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%'  

OTHER TIPS

Try the following:

UPDATE `saleslog` SET `status` = TRIM(`status`);
SELECT * FROM `saleslog` WHERE `status` = 'Pending';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top