Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy column from two separate tables into new table

Status
Not open for further replies.

Naoise

Programmer
Dec 23, 2004
318
IE
tbl1
A_ID | foo

tbl2
B_ID | bar

tbl3 Target table
A_ID | B_ID

How do I create tbl3? tbl1 and tbl2 will always have the same amount of rows.
 
If you want every combination of A_ID and B_ID
Code:
INSERT INTO tbl3 (A_ID, B_ID)
Select tbl1.A_ID, tbl2.B.ID
From tbl1, tbl2
 
Not really looking for every combo. I have :

tbl1
A_ID | foo
1
2
3

tbl2
B_ID | bar
1
2
3

Looking for
tbl3 Target table
A_ID | B_ID
1 1
2 2
3 3

but the sql above yields

tbl3 Target table
A_ID | B_ID
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

Any thoughts?
 
any thoughts? yes!

please describe how to determine which rows of table 1 should be matched to which rows of table 2

is it by equality of their respective ID column values?

and what do you want done with a row from one table that doesn't match a row in the other?



r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top