PedroC88
PedroC88

Reputation: 3829

T-SQL Join Query

I have been trying to write a query for a view but I can't seem to get it... I have two tables that I need to join... but what I need is that for every ID in table 1 I get all records on table 2. For Example:

 Table 1       Table 2
  Jhon          Car
  Bill          House
                Jet
  

I would like to get:

  Table 3
  Jhon   Car
  Jhon   House
  Jhon   Jet
  Bill   Car
  Bill   House
  Bill   Jet

P.S. Data on both tables can vary. P.S.S. Table 1 is actually a Left Outer Join between two other tables where the first table contains the indexes and the second contains the field used to create relation to Table 2.

Upvotes: 1

Views: 176

Answers (4)

Exoas
Exoas

Reputation: 181

Try this

select * from table1, table2

or use a CROSS JOIN if database supports it

Upvotes: 3

odiseh
odiseh

Reputation: 26517

select columns you want to get
from Table1 Cross Join Table2

Upvotes: 2

Quassnoi
Quassnoi

Reputation: 425251

SELECT  *
FROM    table1
CROSS JOIN
        table2

Upvotes: 2

Martin Smith
Martin Smith

Reputation: 452957

You need a CROSS JOIN for this (AKA Cartesian Product).

SELECT t1.col, t2.col
FROM Table1 t1 cross join Table2 t2

Upvotes: 6

Related Questions