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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Compare 2 tables

Compare 2 tables

Scheduled Pinned Locked Moved Database
tutorialquestion
4 Posts 3 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
    alwinSCH
    wrote on last edited by
    #1

    Hi, I have 2 Tables with each his own columns but they have both 1 identical column I want to make a 3th table with the identical columns in but not twice the same! For example: Table 1: ID1,Title,pages Table 2: ID2,Title,Author Table 3: ID3,Title (but when my title is the same in table1 and table2 i only want to insert it once) So i thought, I insert whole table1 in table3 then with a cursor, run through table2 and if i don't find the value in table3 insert Title from table2 in Table3 Is there another work around? Thanks, A.

    P C 2 Replies Last reply
    0
    • A alwinSCH

      Hi, I have 2 Tables with each his own columns but they have both 1 identical column I want to make a 3th table with the identical columns in but not twice the same! For example: Table 1: ID1,Title,pages Table 2: ID2,Title,Author Table 3: ID3,Title (but when my title is the same in table1 and table2 i only want to insert it once) So i thought, I insert whole table1 in table3 then with a cursor, run through table2 and if i don't find the value in table3 insert Title from table2 in Table3 Is there another work around? Thanks, A.

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      Are the IDs in tables 1 & 2 the same? If not, what value will you insert into column ID3 in table 3 when you find matching rows?

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      1 Reply Last reply
      0
      • A alwinSCH

        Hi, I have 2 Tables with each his own columns but they have both 1 identical column I want to make a 3th table with the identical columns in but not twice the same! For example: Table 1: ID1,Title,pages Table 2: ID2,Title,Author Table 3: ID3,Title (but when my title is the same in table1 and table2 i only want to insert it once) So i thought, I insert whole table1 in table3 then with a cursor, run through table2 and if i don't find the value in table3 insert Title from table2 in Table3 Is there another work around? Thanks, A.

        C Offline
        C Offline
        Chetan Patel
        wrote on last edited by
        #3

        Insert into table3 (ID3,Title,xxx) Select ID1,Title,pages from Table1 Union (Select ID1,Title,author from Table2 Where Title Not In (Select Distinct Title From Table1))

        Best Regards, Chetan Patel

        A 1 Reply Last reply
        0
        • C Chetan Patel

          Insert into table3 (ID3,Title,xxx) Select ID1,Title,pages from Table1 Union (Select ID1,Title,author from Table2 Where Title Not In (Select Distinct Title From Table1))

          Best Regards, Chetan Patel

          A Offline
          A Offline
          alwinSCH
          wrote on last edited by
          #4

          Thank You, I was looking way to far, for a solution...

          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