I have the following query
Suppose I have two tables:
Suppliers:
id_supplier | name |
---|---|
1 | Supplier 1 |
2 | Supplier 2 |
3 | Supplier 3 |
Dates
id_pk | date |
---|---|
1 | 2022-12-29 |
2 | 2022-12-30 |
2 | 2022-12-31 |
For each dates, how can get a result set that lists all suppliers per date as follows?
date | supplier |
---|---|
2022-12-29 | Supplier 1 |
2022-12-29 | Supplier 2 |
2022-12-29 | Supplier 3 |
2022-12-30 | Supplier 1 |
2022-12-30 | Supplier 2 |
2022-12-30 | Supplier 3 |
2022-12-31 | Supplier 1 |
2022-12-32 | Supplier 2 |
2022-12-33 | Supplier 3 |
In essence a list of all combinations for the two columns from two different tables?
CodePudding user response:
That's a simple CROSS JOIN:
select date, name from Dates, Suppliers