mysql DISTINCT & ORDER BY

Post Reply
bill-lancaster
Posts: 34
Joined: Tuesday 26th September 2017 3:17pm

mysql DISTINCT & ORDER BY

Post by bill-lancaster » Sunday 24th June 2018 9:14am

I hope it's not a problem posting a mysql issue here!
I have a table 'transactions' with a number of fields including 'TransRef and TransDate). I want to select 'TransRef' as DISTINCT and ORDER BY TransDate.
I've read a number of learned items on this but can't solve the problem.
For example, the table could look like this:-
TransRef TransDate otherfields
0123 12/31/2017
0123 12/31/2017
0144 01/30/2017
0144 01/30/2017
0110 03/10/2017
0110 03/10/2017

This is the result I'm seeking
0144 01/30/2017
0110 03/10/2017
0123 12/31/2017

User avatar
jornmo
Site Admin
Posts: 173
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: mysql DISTINCT & ORDER BY

Post by jornmo » Sunday 24th June 2018 10:10am

This seems to work:
SELECT DISTINCT TransRef, TransDate FROM Transactions ORDER BY TransDate;

bill-lancaster
Posts: 34
Joined: Tuesday 26th September 2017 3:17pm

Re: mysql DISTINCT & ORDER BY

Post by bill-lancaster » Sunday 24th June 2018 5:00pm

Thank you so much.
I thought that was where I'd started - must have been mistaken
Thanks again

User avatar
jornmo
Site Admin
Posts: 173
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: mysql DISTINCT & ORDER BY

Post by jornmo » Monday 25th June 2018 1:18pm

Your very welcome.

Post Reply