WHERE子句中的’=’运算符不返回精确匹配。

huangapple go评论98阅读模式
英文:

WHERE clause with '=' operator doesn't return exact match

问题

我尝试了一个带有WHERE子句的SELECT,用于搜索一个错误的字符串,但结果显示了正确的字符串,进一步的测试显示WHERE子句中的=运算符不能返回精确匹配。

我尝试搜索解决方案,但在Google或Stack Overflow中找不到任何解决方法。

简化示例

SELECT * 
FROM LoginCredential 
WHERE UserID = 'ad' 

结果

英文:

I tried a SELECT with a WHERE clause searching for a wrong string but the result showed the right string, which further testing showed the WHERE clause with the = operator doesn't return the exact match.

I have tried to search for solutions but can't find any through Google or Stack Overflow.

Simplified example

SELECT * 
FROM LoginCredential 
WHERE UserID = 'ad' 

The result

答案1

得分: 0

你的问题似乎已经在这里被提出并有答案:https://stackoverflow.com/questions/1831105/how-to-do-a-case-sensitive-search-in-where-clause-im-using-sql-server

供您参考:

SELECT *
FROM LoginCredential
WHERE UserID = 'ad' COLLATE SQL_Latin1_General_CP1_CS_AS
英文:

You question appears to have already been asked and has an answer here https://stackoverflow.com/questions/1831105/how-to-do-a-case-sensitive-search-in-where-clause-im-using-sql-server

For your easy reference:

SELECT *
From LoginCredential
WHERE UserID = 'ad'  COLLATE SQL_Latin1_General_CP1_CS_AS

答案2

得分: -3

如果您正在使用MySQL,看起来您创建了一个大小写不敏感的数据库,比如utf8mb4_general_ci,ci表示大小写不敏感,请更改为utf8mb4_general_cs(大小写敏感)。

英文:

If you are using MySQL, looks like you create a DB in case insensitive, like utf8mb4_general_ci, ci means case insensitive, change to utf8mb4_general_cs (case sensitive)

huangapple
  • 本文由 发表于 2023年2月27日 11:14:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75576489.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定