fire
fire

Reputation: 21531

Where binary in SQL

I have an SQL statement:

SELECT * FROM customers WHERE BINARY login='xxx' AND password='yyyy'

There are no blob/binary fields in the table, do I need the BINARY after the WHERE what else does it do?

Upvotes: 21

Views: 29878

Answers (3)

DVK
DVK

Reputation: 129403

https://dev.mysql.com/doc/refman/8.0/en/cast-functions.html#operator_binary

The BINARY operator casts the string following it to a binary string. This is an easy way to force a comparison to be done byte by byte rather than character by character. BINARY also causes trailing spaces to be significant.

Upvotes: 9

Anthony Forloney
Anthony Forloney

Reputation: 91786

BINARY is a built-in keyword that after your WHERE clause that forces a comparison for an exact case-sensitive match.

As a side note, you can also make columns case-sensitive by adding the BINARY keyword when you create your table.

Upvotes: 27

Thiago Belem
Thiago Belem

Reputation: 7832

SELECT 'user' = 'UsEr' // true
SELECT BINARY 'user' = 'UsEr' // false

Upvotes: 7

Related Questions