SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: MySQL Select all rows which IDs aren't found in second table

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Select all rows which IDs aren't found in second table

    I want to select all the rows from Table 1 that don't have their ID in a second table. Such as:

    Table1
    -ID
    -Name

    Table2-
    -ID
    -Table1ID
    -Stuff

    I need to find all the Table1 entries that don't have an ID in Table2 under "Table1ID".

  2. #2
    From Italy with love bronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    8,605
    Mentioned
    76 Post(s)
    Tagged
    4 Thread(s)
    What you need is a LEFT JOIN

  3. #3
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,463
    Mentioned
    35 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by guido2004 View Post
    What you need is a LEFT JOIN
    or a NOT EXISTS subquery
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

Bookmarks

Posting Permissions

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