Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2006
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts

    display unique items?

    Hey guys n gals, I have two tables,

    table1
    idnum, detail1, detail2, detail3
    1,bla,bla,bla
    2,bla,bla,bla
    3,bla,bla,bla
    6,bla,bla,bla
    7,bla,bla,bla
    9,bla,bla,bla
    10,bla,bla,bla


    table2
    idnum
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12

    table2 has more idnum values than in table1, and I need to make a list of all the values not found in table 2.

    In the above table example I would like the query to display
    4,5,8,11,12

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You can use a subquery if your version of MySQL is >= 4.1:

    Code:
    SELECT table2.idnum
    FROM table2
    WHERE not exists (SELECT * FROM table1 WHERE table1.idnum = table2.idnum)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •