Kenth John Israel
Kenth John Israel

Reputation: 1333

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 |

Upvotes: 1

Views: 21

Answers (2)

Shaharyar
Shaharyar

Reputation: 12439

use CROSS JOIN:

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

Upvotes: 2

Andrews B Anthony
Andrews B Anthony

Reputation: 1381

use the below query to get desired results

select t1.name as name,t2.date as date 
from Coustomers t1 
join Calendar t2 on 1=1

Upvotes: 1

Related Questions