SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast daliren's Avatar
    Join Date
    Oct 2001
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry One blank field tosses out entire result

    My query looks like this:

    SELECT td.therapistId, td.tdId, td.dYear, s.school, d.degree

    FROM TherapistDegree AS td, Degree AS d, School AS s

    WHERE td.schoolId = s.schoolId AND td.degreeId = d.degreeId AND td.therapistId IN( $tIds )

    ORDER BY dYear DESC, degree ASC

    Everything works fine except for those pesky therapists who only enter their degree and no school. without a school Id in TherapistDegree, no degree will display at all, even if it is there. How can I modify this query to allow users to leave td.schoolId blank and still see their degree?
    cheers,

    Darren Cassidy

  2. #2
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to do a LEFT OUTER JOIN.

    SELECT td.therapistId, td.tdId, td.dYear, s.school, d.degree
    FROM TherapistDegree AS td
    LEFT OUTER JOIN Degree AS d ON td.degreeId = d.degreeId
    LEFT OUTER JOIN School AS s ON td.schoolId = s.schoolId
    WHERE td.therapistId IN( $tIds )
    ORDER BY dYear DESC, degree ASC


    This way if they forget to enter their school and/or degree they will still be listed.

  3. #3
    SitePoint Enthusiast daliren's Avatar
    Join Date
    Oct 2001
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks!

    U R da man!
    cheers,

    Darren Cassidy


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
  •