NeshaSerbia
NeshaSerbia

Reputation: 2542

Sql server combine two tables and multiple

I Have two tables:

Table A:

EmloyeeName
John
Mike
Bruce

Table B:

Date
2018-10-25  
2018-10-26  
2018-10-27  
2018-10-28  
2018-10-29  
2018-10-30  
2018-10-31  

I want to have:

EmployeeName   Date
John  2018-10-25  
John  2018-10-26  
John  2018-10-27  
John  2018-10-28  
John  2018-10-29  
John  2018-10-30  
John  2018-10-31  
Mike  2018-10-25  
Mike  2018-10-26  
Mike  2018-10-27  
Mike  2018-10-28  
Mike  2018-10-29  
Mike  2018-10-30  
Mike  2018-10-31 
...

Which query to use?

Upvotes: 0

Views: 45

Answers (3)

Suraj Kumar
Suraj Kumar

Reputation: 5653

You can do it by cross join as shown below

SELECT a.name, b.date
FROM TableA a CROSS JOIN
     TableB b
ORDER BY a.name;

Hope this will help you.

Upvotes: 0

skarakas
skarakas

Reputation: 154

You can try this.

select t1.EmloyeeName,t2.Date 
from TableA t1, TableB t2

Upvotes: 0

Yogesh Sharma
Yogesh Sharma

Reputation: 50173

You need CROSS JOIN :

SELECT a.name, b.date
FROM a CROSS JOIN
     b
ORDER BY a.name;

Upvotes: 5

Related Questions