SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Intersection

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Cumbria, UK
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Intersection

    How can I list all of the rows in table1 that do not have a corresponding record in table2?

    If table1 contains employee data including a number, and table2 contains one or more records for each employee linked by the number, I need to list of employees with no records i.e. no records in table2 with that employee's number.

    An intersection would do the trick (all numbers that appear in table1 but not in table2) but I'm unsure of the syntax

    Thanks

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Here is a basic example of how it can be done:

    Code:
    SELECT t1.* FROM first_table as t1
      LEFT JOIN second_table as t2
        ON t2.table2_field = t1.table1_field
    WHERE t2.table2_field IS NULL
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Cumbria, UK
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks

    I have adapted that and its what I wanted.
    Thanks for the speedy response!

    Paul


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
  •