Reputation: 51
I have an table like this
I have been try this sql code
SELECT id,lat,lng,name,MIN(hitung) AS Smallest FROM open_list;
but the result give me wrong query
what i wanna do is being like this :
Upvotes: 0
Views: 33
Reputation: 324620
You could do this:
SELECT id,lat,lng,name,hitung
FROM open_list
ORDER BY hitung ASC
LIMIT 1
Or, if you want to do more complex stuff, start with this:
SELECT id,lat,lng,name,hitung
FROM open_list
JOIN (
SELECT MIN(hitung) as hitung
FROM open_list
) tmp USING (hitung)
Upvotes: 2
Reputation: 34774
When you do not GROUP BY
non-aggregate values from your SELECT
list, the returned values are arbitrary. You can add a GROUP BY
but that will return multiple records, you can use ORDER BY
and LIMIT
to get what you're after:
SELECT id,lat,lng,name,hitung
FROM open_list
GROUP BY id,lat,lng,name
ORDER BY hitung ASC
LIMIT 1;
Upvotes: 1