Home > Software design >  How to create a sub-query with a combination of two tables
How to create a sub-query with a combination of two tables

Time:11-14

I need help coming up with a query that join 2 tables and comes out with a matrix like this:

table 1:

month
january-2022
february-2022
march-2022

table 2:

client_id
100123
100124
100125

table 3 outcome:

month           client_id
january-2022    100123
february-2022   100123
march-2022      100123
january-2022    100124
february-2022   100124
march-2022      100124
january-2022    100125
february-2022   100125
march-2022      100125

Any ideas on how could I do that via Redshift SQL? Thanks in advance

edit: I've corrected the expected results, it was wrong, thanks @thorsten kettner for pointing it out.

CodePudding user response:

select t1.month, t2.client_id from table1 t1 cross join table2 t2 in proper standard SQL. (We stopped using commas in the from clause some decades ago.) – Thorsten Kettner 2 days ago

Thorsten Kettner solved it in the comments, thanks.

  • Related