Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL DISTINCT and whitespace

Tags:

mysql

distinct

Consider the following queries

INSERT INTO DummyTable (TextColumn) VALUES ('Text');
INSERT INTO DummyTable (TextColumn) VALUES ('Text ');

SELECT DISTINCT TextColumn FROM DummyTable

Notice that the second insert contains a whitespace: 'Text '

But DISTINCT ignores the space and returns only one row 'Text' - how do you make DISTINCT not to ignore the whitespace?

like image 739
Mirek Avatar asked Aug 08 '12 06:08

Mirek


1 Answers

Turns out I was looking for a BINARY keyword, the DISTINCT then compares raw binary values, including spaces.

SELECT DISTINCT BINARY TextColumn FROM DummyTable
like image 133
Mirek Avatar answered Nov 14 '22 08:11

Mirek