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.

0

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This does not work in IBM DB2
2

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

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

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.