MySQL Forums
Forum List  »  Newbie

Select with sort by earliest date and second column
Posted by: Tim Oron
Date: October 17, 2021 02:51PM

Hi experts!

It would be great, if someone could help me with a little problem:
Here is a table with some entries.

| group_name | article | date |

| Group C | New World | 2021-10-05 |
| Group A | Old World | 2021-10-14 |
| Group B | No World | 2021-10-01 |
| Group B | First World | 2021-10-17 |
| Group A | Last World | 2021-10-11 |
| Group A | One World | 2021-10-10 |
| Group C | All Worlds | 2021-10-29 |


How I can make a query to get the following result?

(Sorted by group_name ("grouped" but without making a group) but orderd by earliest date

So how do I get this result:


| group_name | article | date |

| Group B | No World | 2021-10-01 |
| Group B | First World | 2021-10-17 |
| Group C | New World | 2021-10-05 |
| Group C | All Worlds | 2021-10-29 |
| Group A | Old World | 2021-10-10 |
| Group A | Last World | 2021-10-11 |
| Group A | One World | 2021-10-14 |


If I order by group_name and date, I get A, B, C or C, B, A and then the dates- wrong
If I order by date and then group_name, I get sorted dates and group_name mixed - wrong
If I group group_name and order by date, I just get 3 results. - wrong
Can someone give me a hint how I can solve my problem?

Thanks in advance!

Options: ReplyQuote


Subject
Written By
Posted
Select with sort by earliest date and second column
October 17, 2021 02:51PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.