Need help with one SQL query for two tables !

Discussion in 'MySQL' started by Jona, Aug 10, 2007.

  1. #1
    I need to get all members from members table except
    members with an id found in blocked table's member_id field ...

    Can it be done in ONE query and if ... How should the query look?

    Sample db structure:

    Table 1: members | Field: id, name, email, url
    Table 2: blocked | id, member_id

    $MySQL = "
    SELECT id, name, email, url FROM members
    WHERE [id NOT found in blocked's member_id field - I'M LOST HERE]
    ORDER BY id
    ";

    Any sql guru here? - Sample snippet pleeeease :rolleyes:
     
    Jona, Aug 10, 2007 IP
  2. The Webmaster

    The Webmaster IdeasOfOne

    Messages:
    9,516
    Likes Received:
    718
    Best Answers:
    0
    Trophy Points:
    360
    #2
    Try this -

    OR Use SQL 'Join' function

     
    The Webmaster, Aug 10, 2007 IP
  3. Jona

    Jona Well-Known Member

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Thank you Webmaster, this is just what I needed :)

    Are they exactly the same to use, or is one better than the other,
    thinking about performance, speed etc, etc ?
     
    Jona, Aug 10, 2007 IP
  4. horatiub

    horatiub Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I think the second query will perform a little better, but it won't make a huge difference
     
    horatiub, Aug 10, 2007 IP
  5. The Webmaster

    The Webmaster IdeasOfOne

    Messages:
    9,516
    Likes Received:
    718
    Best Answers:
    0
    Trophy Points:
    360
    #5
    'Join' is always good to use.
    But since you have only two table and few fields you can use any of them..
     
    The Webmaster, Aug 10, 2007 IP
    Will.Spencer likes this.