Results 1 to 8 of 8

Thread: Join help

  1. #1
    Join Date
    Jan 2012
    Posts
    52

    Unanswered: 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 04:45.

  2. #2
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    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/2012
    Wim

    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

  3. #3
    Join Date
    Jan 2012
    Posts
    52
    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

  4. #4
    Join Date
    Jan 2012
    Posts
    52
    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')

  5. #5
    Join Date
    Mar 2004
    Posts
    162
    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

  6. #6
    Join Date
    Jan 2012
    Posts
    52
    Quote Originally Posted by mrpcguy View Post
    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

  7. #7
    Join Date
    Mar 2004
    Posts
    162
    i forgot a column name on the WHERE statement but i guess you already figured that out

    WHERE EXPORT.COMPANY LIKE '%11%'

  8. #8
    Join Date
    Jan 2012
    Posts
    52
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •