#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    231
    Rep Power
    18

    Subtract records


    Hi,

    How do I subtract 2 sets of records in SQL? For example,

    The first sql returns the output below.

    # Name Age ID
    1 Mary 24 2982
    2 John 32 9381
    3 Kevin 31 4872
    4 May 42 8281
    5 Bill 27 1747

    The second sql returns the output below.

    # Name Age ID
    1 Henry 12 2993
    2 Mary 22 2982
    3 Karen 33 7377
    4 June 38 8772
    5 May 23 8281

    Since Mary and May in the second output set have the same ID in the first output set. I would like to remove those records in the first output set. How do I write the query to remove those records so that the output is shown in below? Thank you.

    2 John 32 9381
    3 Kevin 31 4872
    4 May 42 8281
  2. #2
  3. Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    Morton Grove, IL, USA
    Posts
    23
    Rep Power
    0
    Could you please provide the queries? Otherwise it is difficult to reply...
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2016
    Location
    United Kingdom
    Posts
    9
    Rep Power
    0
    Originally Posted by soap
    Hi,

    How do I subtract 2 sets of records in SQL? For example,

    The first sql returns the output below.

    # Name Age ID
    1 Mary 24 2982
    2 John 32 9381
    3 Kevin 31 4872
    4 May 42 8281
    5 Bill 27 1747

    The second sql returns the output below.

    # Name Age ID
    1 Henry 12 2993
    2 Mary 22 2982
    3 Karen 33 7377
    4 June 38 8772
    5 May 23 8281

    Since Mary and May in the second output set have the same ID in the first output set. I would like to remove those records in the first output set. How do I write the query to remove those records so that the output is shown in below? Thank you.

    2 John 32 9381
    3 Kevin 31 4872
    4 May 42 8281

    You are looking for MINUS operator based on the ID. See this https://www.techonthenet.com/oracle/minus.php with simple example.

IMN logo majestic logo threadwatch logo seochat tools logo