Home > front end >  i want to join every row of a table with another one in a specific order
i want to join every row of a table with another one in a specific order

Time:05-27

I have 2 tables :

years:
id   name
1    2022
2    2023
3    2024
4    2025
5    2026

and months :

id   name
1    jan
2    feb
3        mar

4 apr 5 jun 6 jul ...

i want to join every row from years to a row from months. something like this :(with this order)

2022 jan
2022 feb
2022 mar
2022 apr
...
2023 jan
2023 feb
....

Please help

CodePudding user response:

That's cross join (Cartesian product).

select y.name as year,
       m.name as month
from years y cross join months m
order by y.name, m.id
  • Related