开发者

mySql new rows can only be searched with LIKE, has anyone had this before?

A bit of background I'm running mySQL on a mac I have a few databases setup that have been working okay I have recently created a new table from a sqlDump from another server. I am having an issue with new rows that equal = a value that I know exists

e.g. Table setup

id=1 name='dave' - already exists in database

id=2 name='john' - I add a new row

Following are the sql I tried with results...

Select * from tablename where id=1 -- I get the correct Dave result.

Select * from tablename where `name` = 'dave' -- I get the correct Dave result.

Select * from tablename where id=2 -- I get the correct John result.

Select * from tablename where `name` like 'joh%' -- I get the correct John result.

Select * fro开发者_如何学Pythonm tablename where `name` = 'john' -- (No result!) eek!

Anyone seen this before? it's in the database but a direct match on the name field is not yielding a result.

Thanks in advance M


One possibility: there could be a trailing space after 'john' in the name column.

One way to check that:

select `name`,char_length(`name`), char_length('john')
from tablename 
where id = 2


An easy way to not have to deal with that problem would be to trim your input (if you don't expect to ever have preceding or trailing white space.

In that case you could have a query like:

Select * from tablename where trim(`name`) = trim('john')


I agree with the comments on your question, that it is most likely a hidden space or something similar. If you include the column definitions so we can check the data that your using with the types we could help more. Remove the entry and and retry with a different name other than john and see if you can replicate the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜