-1

I have two tables look like this:

Year    Month   
--------------
2021     1     
2021     2   
2021     3     
2021     4   
2021     5      
2021     6    
Planet
-------
Mercury
Venus
Earth
Mars

There is no relation between the two tables but i want to use them to create an SQL selection with a break down of the columns Year and Month based on the values of the table Planet like the following:

Year    Month   Planet
2021    1       Mercury
2021    1       Venus
2021    1       Earth
2021    1       Mars
2021    2       Mercury
2021    2       Venus
2021    2       Earth
2021    2       Mars
...

Since we cannot simply join the two table is there a way to achieve this?

2 Answers2

1

You are looking for CROSS JOIN:

select *
from table1 t1 cross join
     table2 t2;

You could also implement this using a regular JOIN but with a condition that is always true:

select *
from table1 t1 join
     table2 t2
     on 1=1;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

No join (cross join by default)

SELECT <* or your fields> FROM <t1>,<t2> ORDER BY <want you  want>
Dri372
  • 1,275
  • 3
  • 13