MySQL SELECT * FROM WHERE 没有找到所有记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23400613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SELECT * FROM WHERE does not find all records
提问by user3387040
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".
尽管状态列中有数百行具有“待处理”值,但我只显示了 3 条记录。当我寻找“待定”以外的价值时,也会发生同样的情况。
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.
然后显示大多数(如果不是全部)记录。在 Pending 值前后绝对没有空格或任何其他字符。
I am wondering if table "saleslog" needs to be repaired and if so, how? I'm kind of new to SQL.
我想知道表“saleslog”是否需要修复,如果需要,如何修复?我对 SQL 有点陌生。
回答by cmreynol
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:
字段中可能存在您看不到的隐藏字符,例如制表符、回车符或换行符。您是否尝试过对该领域进行更新以尝试纠正它?也许尝试运行下面的更新查询,然后SELECT
再次运行您的查询:
UPDATE saleslog SET status = 'Pending' WHERE status LIKE '%Pending%'
回答by potashin
Try the following:
请尝试以下操作:
UPDATE `saleslog` SET `status` = TRIM(`status`);
SELECT * FROM `saleslog` WHERE `status` = 'Pending';