MySQL DISTINCT and spaces

Consider the following queries

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

SELECT DISTINCT TextColumn FROM DummyTable

Note that the second insert contains a space: “Text”

But DISTINCT ignores space and returns only one line of "Text" - how do you make DISTINCT not to ignore spaces?

+5
source share
2 answers

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

SELECT DISTINCT BINARY TextColumn FROM DummyTable
+5
source
SELECT DISTINCT replace(TextColumn,' ','') FROM DummyTable
0
source

All Articles