User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 456,197 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,943 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 902 | Replies: 3
Reply
Join Date: Apr 2007
Posts: 6
Reputation: pink_zippy_123 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
pink_zippy_123 pink_zippy_123 is offline Offline
Newbie Poster

Help Sql Joins

  #1  
May 6th, 2007
Hi,

I am currently trying to write some sql that includes a where clause to limit responses but will leave blanks where there is no match. I will include the code so its easier to understand:

SELECT DISTINCT teacher.teachername, student.studentname, results.grade FROM teacher INNER JOIN student ON teacher.teachername = student.teachername INNER JOIN results ON student.studentname = results.studentname WHERE results.grade = 'A';

I basically want all teachers names to be displayed, but only students that have got A's to be displayed next to them, and any that do not have any A Grade students to have a blank box next to them! I have tried using left joins, right joins, and outer joins and nothing has worked...all I end up with is only teachers names listed that have A Grade students. Any ideas? Any help will be greatly appreciated!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2007
Posts: 28
Reputation: cfAllie is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cfAllie cfAllie is offline Offline
Light Poster

Re: Sql Joins

  #2  
May 12th, 2007
SELECT     DISTINCT teacher.teachername, student.studentname, results.grade 
FROM     teacher LEFT JOIN
      (
          student INNER JOIN results 
    ON student.studentname = results.studentname
    AND results.grade = 'A'
      ) 
      ON teacher.teachername = student.teachername 
Reply With Quote  
Join Date: Apr 2007
Posts: 6
Reputation: pink_zippy_123 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
pink_zippy_123 pink_zippy_123 is offline Offline
Newbie Poster

Re: Sql Joins

  #3  
May 12th, 2007
Thats great it now works...thanks a lot!!
Reply With Quote  
Join Date: Mar 2007
Posts: 28
Reputation: cfAllie is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cfAllie cfAllie is offline Offline
Light Poster

Re: Sql Joins

  #4  
May 12th, 2007
Welcome !
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MySQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 3:50 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC