How to get the difference between two similar tables (complement)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #1

    How to get the difference between two similar tables (complement)

    Dear All,
    I am having a bit problem with a simple development.
    I am not into Queries but I need this.
    Lets follow the example below

    tble1
    ---------------------------------
    | ID | Name
    ---------------------------------
    | 1 | johny
    ---------------------------------
    | 2 | rony
    ---------------------------------
    | 3 | Anne
    ---------------------------------

    tbl2
    ---------------------------------
    | ID | Name
    ---------------------------------
    | 1 | johny
    ---------------------------------
    | 3 | Anne
    ---------------------------------

    I need the query of complement: The returned result would be
    ---------------------------------
    | ID | Name
    ---------------------------------
    | 2 | rony
    ---------------------------------

    Please I need the solution
    Best Regards,
    Johny
  • acoolguy
    New Member
    • Jul 2010
    • 13

    #2
    We need more information like whats the fields called and what your trying to do exactly?

    Comment

    • johny10151981
      Top Contributor
      • Jan 2010
      • 1059

      #3
      The query would be,

      Code:
      SELECT M.ID
      FROM tble1 AS M
      WHERE M.ID NOT
      IN (
      SELECT P.ID
      FROM tbl2 AS P
      )
      Regards,
      Johny

      Comment

      Working...