SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    971
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question about a query

    How can I adjust the query below to return results if stories.volunteer_id is null in a reccord?

    Code MySQL:
    SELECT stories.title, stories.id as 'id', stories.content as 'description', organization_name, partner_id, volunteer_id, concat(first_name, ' ', last_name ) as 'name', partners.city as 'city',partners.country as 'country'
     
    FROM stories, partners, volunteers
     
    WHERE stories.volunteer_id=volunteers.id 
     
    AND stories.partner_id=partners.id
     
    ORDER BY id DESC

    Thanks E

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,334
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    SELECT ...
      FROM stories
    INNER
      JOIN partners
        ON partners.id = stories.partner_id
    LEFT OUTER
      JOIN volunteers
        ON volunteers.id = stories.volunteer_id
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    971
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks so much. You are expanding my horizons. E


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
  •