SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot HenriIV's Avatar
    Join Date
    Jun 2004
    Location
    France
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question stupid simple query

    Hi,

    I don't remember how to do a query like this:
    table a (the owner)
    a_id, name

    table b (animals)
    b_id, petname, a_id

    I just want to select the owners that have no pets. Any idea?

  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,

    I think that something like the query below should do the trick.

    Code:
    SELECT tA.* FROM owners_table as tA
      LEFT JOIN animals_table as tB ON tB.a_id = tA.a_id
    WHERE tB.a_id IS NULL
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Zealot HenriIV's Avatar
    Join Date
    Jun 2004
    Location
    France
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks lilleman, I get an Empty set but it must be close to the solution

  4. #4
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The query above is correct, do you have owners listed in the owners table who are not listed at all in the animals table?

    Can we see some sample data from both tables?

  5. #5
    SitePoint Zealot HenriIV's Avatar
    Join Date
    Jun 2004
    Location
    France
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's right, I just made a mistake modifying name!
    thanks guys!


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
  •