I have the following sql:
SELECT `id` FROM `exchange` WHERE `photo` = 1 ORDER BY `id` DESC LIMIT 18
How can I only get distinct location values?
For example doing this but it returns an error:
SELECT `id`, distinct(`location`) FROM `exchange` WHERE `photo` = 1 ORDER BY `id` DESC LIMIT 18
Example table:
id location
1 7
2 8
3 4
4 4
5 2
6 32
Example result (when LIMIT 5):
6,5,4,2,1
DISTINCTworks for the whole row, not for the value of each column. Remove the columnIDand you will have unique location.UPDATE 1
You can use AGGREGATE FUNCTION like MAX() and grouped them by their
ID. Try this again,