i want to select distinct customer_id
order by either s.no
or time
or anyhow
s.no customer_id time
1 3 100001
2 2 100002
3 4 100003
4 3 100004
5 2 100005
i am using
select distinct(customer_id) from table_name order by time DESC
and it is giving the answer as 4 2 3
but as i want it should be 2 3 4
So your problem statement is "You want the list of customer_id, sorted in descended order from their largest time value", right?
SELECT customer_id, MAX(time)
FROM table_name
GROUP BY customer_id
ORDER BY MAX(time) DESC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With