Kenth John Israel Kenth John Israel - 7 months ago 24
SQL Question

Dates per customer

Customers table:

| id | name |
---------------------
| 1 | John |
| 2 | Mike |


Calendar table:

| date |
--------------------
| 2015-01-01 |
| 2015-01-02 |
| 2015-01-03 |





Question: How can I get this result?

Desired result:

| name | date |
------------------------
| John | 2015-01-01 |
| John | 2015-01-02 |
| John | 2015-01-03 |
| Mike | 2015-01-01 |
| Mike | 2015-01-02 |
| Mike | 2015-01-03 |

Answer

use CROSS JOIN:

SELECT 
    Customers.name, 
    Calendar.date
FROM Customers 
CROSS JOIN Calendar