| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

01-17-12, 02:45
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 44
|
|
|
Join help
|
|
Hi guys,
I am trying to make a join in between 2 tables. One table which we can called func has 2 columns a and column b.
The other table which is called export has 16 columns. I will like to make a join in these tables and insert the result of the join into another table i have.
The table that is going to have the information has 4 columns, so I will get 1 column information from table export, and the other 2 column from table func, the other column shall be left in blank for the time being.
The problem is also that when i make a select from table export, there are only some values i want to get, this are values from a period where there is only the periods 11.
Select Company, A and B
FROM FUNC, EXPORT where period = '1101', '1102', '1103'
insert into new table?
does anyone here can give me a hand?
Thanks in advance.
|
Last edited by buzmay; 01-17-12 at 03:45.
|

01-17-12, 03:53
|
|
Registered User
|
|
Join Date: Nov 2004
Posts: 1,280
|
|
Can you give some example data from both tables (including column names) and the column names of the destination table?
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
|
|

01-17-12, 04:07
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 44
|
|
|
|
Sure thanks,
table export has 16 columns which the one that is important only for me is the company column
table func has only 2 columns we can call them a and b.
the table that all the info is going to be is called table info and has the following columns:
company, a, b, result
so from table export which has 16 columns, I only want the column company, and from table func, both of the columns ie a&b
the prblem is that the column company has several companies, and i want only to select the companies that has 11 on its name, this info shall be inserted into the new table info.
Thanks in advance
|
|

01-17-12, 04:39
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 44
|
|
So what I have gotten now is this:
INSERT INTO INFO, SELECT COMPANY, A, B
FROM EXPORT, FUNC,
WHERE EXPORT = FUNC
AND EXPORT.PERIOD IN ('11A', '11B', '11C')
|
|

01-17-12, 04:56
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 140
|
|
try something like
INSERT INTO T1 (COMPANY,A,B)
SELECT COMPANY, A, B
FROM EXPORT INNER JOIN FUNC ON EXPORT.?? = FUNC.??
WHERE EXPORT LIKE '%11%'
replace ?? with columns to be joined
|
|

01-17-12, 05:15
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 44
|
|
Quote:
Originally Posted by mrpcguy
try something like
INSERT INTO T1 (COMPANY,A,B)
SELECT COMPANY, A, B
FROM EXPORT INNER JOIN FUNC ON EXPORT.?? = FUNC.??
WHERE EXPORT LIKE '%11%'
replace ?? with columns to be joined
|
this made the trick, thanks a million, I really appreciate it 
|
|

01-17-12, 05:22
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 140
|
|
i forgot a column name on the WHERE statement but i guess you already figured that out
WHERE EXPORT.COMPANY LIKE '%11%'
|
|

01-17-12, 05:24
|
|
Registered User
|
|
Join Date: Jan 2012
Posts: 44
|
|
Yes I did, but without your guidance I would still be lost. many thanks, and a lot of appreciation for Wim, which also tried to help 
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|