iColdBeZero iColdBeZero - 3 years ago 169
MySQL Question

SELECT DISTINCT skips distinct value

I have a table that contains most recent user searches that looks like this:

id username entity language search_date
44 kira back en 2017-09-26 17:41:35
43 kira back en 2017-09-26 17:41:30
42 kira back en 2017-09-26 17:41:29
41 kira babble en 2017-09-26 17:41:01
40 kira baccalaurean en 2017-09-26 17:40:47
39 kira Time value en 2017-09-26 17:39:34
38 kira bacarıq en 2017-09-26 17:38:51
37 yagami quince en 2017-09-26 17:38:35


I'm trying to fetch ten most rescent unique searches from this table and i'm doing it like this:

SELECT DISTINCT entity, language
FROM users_searches
ORDER BY search_date DESC
LIMIT 0, 10


But for some wierd reson this query skips some values, for example it doesn't include
back
and starts from
babble
, can someone explain me why and how to achieve what i'm trying to do?

UPDATE 1

desired resullt should be something like this:

back, babble, baccalaurean, Time value, bacarıq, quince

Answer Source

This will not work:

SELECT DISTINCT entity, language
FROM users_searches
ORDER BY search_date
DESC LIMIT 0, 10

Because search_date is not in the SELECT DISTINCT.

Does this do what you want?

select entity, language
from users_searches
group by entity_language
order by max(search_date) desc
limit 10;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download