|
-
Aug 18th, 2009, 02:54 PM
#1
Thread Starter
Addicted Member
[RESOLVED] SQL "JOIN" (I think)
I have two tables (simplified below)
Table A
x desc
-----
1 xxx
2 xxx
3 xxx
Table B
desc
-----
abc
def
ghi
I need to insert in to a third table, from these two tables
replacing xxx with abc, def, ghi
so that I have 9 columns inserted in to my third day
ie
Table B
x desc
------
1 abc
2 abc
3 abc
1 def
2 def
3 def
1 ghi
2 ghi
3 ghi
as there are no matching columns in these two tables, I don't know how to join them?
I tried using <> but that didn't seen to work
any help would be appreciated here
Thanks
-
Aug 18th, 2009, 02:58 PM
#2
Re: SQL "JOIN" (I think)
Use a cross join
sql Code:
Insert into TableC select TableA.X, TableB.Desc from TableA, TableB
-
Aug 18th, 2009, 03:02 PM
#3
Thread Starter
Addicted Member
Re: SQL "JOIN" (I think)
cheers Pradeep,
If I wanted to multiply x by a value from table b as well, that would work too yeah?
-
Aug 18th, 2009, 03:06 PM
#4
Re: SQL "JOIN" (I think)
Put whatever you need in the select statement.
e.g.
sql Code:
Insert into TableC select TableA.X * 10, TableB.Desc from TableA, TableB
-
Aug 18th, 2009, 03:08 PM
#5
Thread Starter
Addicted Member
Re: SQL "JOIN" (I think)
Top man!
Still just learning SQL, was confusing myself with all kinds of joins etc
Thanks again!!
-
Aug 18th, 2009, 03:16 PM
#6
Re: [RESOLVED] SQL "JOIN" (I think)
If you just want to see the results without inserting into a third table, just remove that INSERT part
sql Code:
select TableA.X * 10, TableB.Desc from TableA, TableB
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|