SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Utah, USA
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help fixing a simple join query

    This should be easy for you SQL pros:
    I need a list of people who have no property.

    mysql> select * from people;

    +------------+--------------+------+
    | name | phone | pid |
    +------------+--------------+------+
    | Mr Brown | 01225 708225 | 1 |
    | Miss Smith | 01225 899360 | 2 |
    | Mr Pullen | 01380 724040 | 3 |
    +------------+--------------+------+


    mysql> select * from property;

    | pid | spid | selling |
    +------+------+----------------------+
    | 1 | 1 | Old House Farm |
    | 3 | 2 | The Willows |
    | 3 | 3 | Tall Trees |
    | 3 | 4 | The Melksham Florist |
    | 4 | 5 | Dun Roamin |
    +------+------+----------------------+

  2. #2
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Staffordshire, UK & Florida, USA
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this:

    Code:
    SELECT pid, name, phone FROM people LEFT JOIN property ON people.pid = property.pid WHERE property.pid IS NULL


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
  •