Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. INSERT query for a table?(Using two Tables)

INSERT query for a table?(Using two Tables)

Scheduled Pinned Locked Moved Database
helpdatabasetutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chand10
    wrote on last edited by
    #1

    Hi I stuck at an INSERT Query using two tables. I have two tables Table1 and Table2.In Table1 I have 2 columns,one with dupicate value and another with null values.In Table2 I have 2 columns,both the columns have unique values. Now I have to INSERT values from Table2 to Table1 with the corresponding or maching values like Table1 StateCode StateName --------- ---------- AK NULL AK NULL AK NULL AL NULL AL NULL AL NULL CO NULL CO NULL CO NULL Table2 StateCode StateName --------- ---------- AK Alaska AL Alabama AR Arkansas AZ Arizona CA California CO Colorado I have to INSERT values into Table1 in the null column from Table2 w.r.t StateCode. Help me :confused: Suggest me an example. I have not failed. I've just found 10,000 ways that won't work. -Thomas A. Edison Thank u Chandu

    A 1 Reply Last reply
    0
    • C chand10

      Hi I stuck at an INSERT Query using two tables. I have two tables Table1 and Table2.In Table1 I have 2 columns,one with dupicate value and another with null values.In Table2 I have 2 columns,both the columns have unique values. Now I have to INSERT values from Table2 to Table1 with the corresponding or maching values like Table1 StateCode StateName --------- ---------- AK NULL AK NULL AK NULL AL NULL AL NULL AL NULL CO NULL CO NULL CO NULL Table2 StateCode StateName --------- ---------- AK Alaska AL Alabama AR Arkansas AZ Arizona CA California CO Colorado I have to INSERT values into Table1 in the null column from Table2 w.r.t StateCode. Help me :confused: Suggest me an example. I have not failed. I've just found 10,000 ways that won't work. -Thomas A. Edison Thank u Chandu

      A Offline
      A Offline
      andyharman
      wrote on last edited by
      #2

      Hi Chandu Sounds like you need to "update". Something like:

      update Table1 set StateName = Table2.StateName
        from Table2
        where Table2.StateCode = Table1.StateCode
      

      Regards Andy

      If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message".

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups