tbaldw02 tbaldw02 - 1 month ago 4
SQL Question

How to write a SQL query to manipulate data between 2 tables?

I have a use case to query 2 tables in a specific way.

Both tables have a single column.

Table 1 Column 1:

A
B
C


Table 2 Column 1:

1
2
3


I need to structure a query to get it to look like the following:

A 1
A 2
A 3
B 1
B 2
B 3
...


Is this possible in MS SQL Server?

Thanks,

Trent

Answer

It is called CROSS JOIN

Select t1.column1,t2.column1 from Table1 t1
CROSS JOIN Table2 t2

It will produce the Cartesian product between two tables.