2
SELECT * FROM Customers
WHERE City IN ('Paris','London');

How would I change it to match exact case (basically exact match)? i.e. lOnDoN would not be included in the results.

meiryo
  • 11,157
  • 14
  • 47
  • 52

3 Answers3

7

Use BINARY to force a binary (byte for byte) string comparison:

SELECT * FROM Customers
WHERE BINARY City IN ('Paris','London');

Or, if you always want the City column to be case sensitive, consider altering the collation of the column.

2

Not sure if BINARY would work with IN, like this:

SELECT * FROM Customers
WHERE BINARY City IN ('Paris','London')
Aziz Shaikh
  • 16,245
  • 11
  • 62
  • 79
2

You can use BINARY

SELECT * 
FROM Customers
WHERE BINARY City IN ('Paris','London')

BINARY Work like below.

mysql> SELECT 'a' = 'A';
        -> 1
mysql> SELECT BINARY 'a' = 'A';
        -> 0
mysql> SELECT 'a' = 'a ';
        -> 1
mysql> SELECT BINARY 'a' = 'a ';
        -> 0

Please find more info on BINARY

Prabhakar Manthena
  • 2,223
  • 3
  • 16
  • 30