Results 1 to 6 of 6

Thread: [RESOLVED] SQL "JOIN" (I think)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Resolved [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

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: SQL "JOIN" (I think)

    Use a cross join

    sql Code:
    1. Insert into TableC
    2. select TableA.X, TableB.Desc
    3. from TableA, TableB
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    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?

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: SQL "JOIN" (I think)

    Put whatever you need in the select statement.
    e.g.
    sql Code:
    1. Insert into TableC
    2. select TableA.X * 10, TableB.Desc
    3. from TableA, TableB
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: SQL "JOIN" (I think)

    Top man!

    Still just learning SQL, was confusing myself with all kinds of joins etc

    Thanks again!!

  6. #6
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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:
    1. select TableA.X * 10, TableB.Desc
    2. from TableA, TableB
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

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



Click Here to Expand Forum to Full Width