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. find discrepancy between two tables

find discrepancy between two tables

Scheduled Pinned Locked Moved Database
databasetoolshelpquestion
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.
  • S Offline
    S Offline
    sqldba
    wrote on last edited by
    #1

    Hi Experts, I have to find discrepancy between two tables I have Table 1 with columns OrderID Date Quantity Symbol Table 2 with columns OrderID Date Quantity Symbol I want a script to find out a list of OrderIDs present in table1 but not in table 2 and a list of OrderIDs present in table2 but not in table 1. Could any one help me in writing this query? Thanks in advance

    A 1 Reply Last reply
    0
    • S sqldba

      Hi Experts, I have to find discrepancy between two tables I have Table 1 with columns OrderID Date Quantity Symbol Table 2 with columns OrderID Date Quantity Symbol I want a script to find out a list of OrderIDs present in table1 but not in table 2 and a list of OrderIDs present in table2 but not in table 1. Could any one help me in writing this query? Thanks in advance

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

      You can use the IN oprator for that: SELECT * FROM Table1 WHERE OrderID NOT IN ( SELECT OrderID FROM Table2 ) and then reverse the tabels for the other way: SELECT * FROM Table2 WHERE OrderID NOT IN ( SELECT OrderID FROM Table1 )

      --------------------------- Blogging about SQL, Technology and many other things

      N 1 Reply Last reply
      0
      • A Alsvha

        You can use the IN oprator for that: SELECT * FROM Table1 WHERE OrderID NOT IN ( SELECT OrderID FROM Table2 ) and then reverse the tabels for the other way: SELECT * FROM Table2 WHERE OrderID NOT IN ( SELECT OrderID FROM Table1 )

        --------------------------- Blogging about SQL, Technology and many other things

        N Offline
        N Offline
        Naveed Kamboh
        wrote on last edited by
        #3

        If you are on SQL Serer 2005 then you can use Intersetion, Difference and Union rules of Set Theroy. select * from Table1 intersect select * from Table2 It will give you the common records in both select * from Table1 EXCEPT select * from Table2 above will give you difference

        Naveed Kamboh Complexity kills, Write easy code for your self. Punjabi stuff

        A 1 Reply Last reply
        0
        • N Naveed Kamboh

          If you are on SQL Serer 2005 then you can use Intersetion, Difference and Union rules of Set Theroy. select * from Table1 intersect select * from Table2 It will give you the common records in both select * from Table1 EXCEPT select * from Table2 above will give you difference

          Naveed Kamboh Complexity kills, Write easy code for your self. Punjabi stuff

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

          When it is just the orderid's it is faster (performance wise) to just use the IN syntax.

          --------------------------- Blogging about SQL, Technology and many other things

          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