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 rows into single table from two table which has different columns

insert rows into single table from two table which has different columns

Scheduled Pinned Locked Moved Database
tutorial
6 Posts 6 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.
  • A Offline
    A Offline
    abu bdt
    wrote on last edited by
    #1

    i have two tables a and b.a has 7 different columns and b has 20 different columns. i want to insert rows from a to b.how to insert. so plz provide solution

    L S C R A 5 Replies Last reply
    0
    • A abu bdt

      i have two tables a and b.a has 7 different columns and b has 20 different columns. i want to insert rows from a to b.how to insert. so plz provide solution

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Read records from table a and insert them into table b, adding the detail for the extra columns.

      Veni, vidi, abiit domum

      1 Reply Last reply
      0
      • A abu bdt

        i have two tables a and b.a has 7 different columns and b has 20 different columns. i want to insert rows from a to b.how to insert. so plz provide solution

        S Offline
        S Offline
        Simon_Whale
        wrote on last edited by
        #3

        Here is a sample. have done this using SQL Server but it shouldn't be hard to move it too one of the other databases

        create table #tableOne
        (
        id int,
        name varchar(50),
        email varchar(100)
        )

        create table #tableNames
        (
        id int,
        name varchar(50)
        )

        insert into #tableOne values (1, 'simon','simon@email.com')
        insert into #tableOne values (2, 'someone','someone@email.com')

        insert into #tableNames values (3, 'fred')

        insert into #tableOne
        select id, name,''
        from #tablenames

        select *
        from #tableOne

        drop table #tableNames
        drop table #tableOne

        Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

        1 Reply Last reply
        0
        • A abu bdt

          i have two tables a and b.a has 7 different columns and b has 20 different columns. i want to insert rows from a to b.how to insert. so plz provide solution

          C Offline
          C Offline
          coded007
          wrote on last edited by
          #4

          Are they any non null-able columns in table b ? IF they are non null-able columns then follow below code

          INSERT INTO b(<>)
          SELECT <> from a [where <>]

          Mani Prabhakar

          1 Reply Last reply
          0
          • A abu bdt

            i have two tables a and b.a has 7 different columns and b has 20 different columns. i want to insert rows from a to b.how to insert. so plz provide solution

            R Offline
            R Offline
            rashin ghodratzade
            wrote on last edited by
            #5

            INSERT INTO b (field list b) SELECT field list a FROM a

            1 Reply Last reply
            0
            • A abu bdt

              i have two tables a and b.a has 7 different columns and b has 20 different columns. i want to insert rows from a to b.how to insert. so plz provide solution

              A Offline
              A Offline
              Anudeep Jaiswal MCA
              wrote on last edited by
              #6

              Specify Columns Of Table B. Like Insert Into B (Col1,Col2,Col3) Select Col9,Col8,Col7 From A. Please Note That Data Type of Column Should Be Same.

              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