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

165 views Asked by At

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

2

There are 2 answers

2
Stephen Quan On BEST ANSWER

You question appears to have already been asked and has an answer here How to do a case sensitive search in WHERE clause (I'm using SQL Server)?

For your easy reference:

SELECT *
From LoginCredential
WHERE UserID = 'ad'  COLLATE SQL_Latin1_General_CP1_CS_AS
1
Calidan On

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)