So i have to write 3 join if I have 3 conditions and so on, right?

"Scott Noyes" <[EMAIL PROTECTED]> ???
news:[EMAIL PROTECTED] ???...
> Select s.StudentID, s.StudentName from Student s, SubjectGrade sg where
> s.StudentID = sg.StudentID and sg.Subject = 'Maths' and sg.Subject =
'Chem'
> and sg.Grade = 'A'

Take a close look at the WHERE clause: "sg.Subject = 'Maths' and
sg.Subject = 'Chem'" will never return a result - how could the
subject be two different things at the same time?

Here's one way that should work:

SELECT s.StudentID, StudentName
FROM Student s
  JOIN StudentGrade sg1 USING (StudentID)
  JOIN StudentGrade sg2 USING (StudentID)
WHERE
  sg1.Subject = 'Maths' AND sg1.Grade = 'A'
  AND sg2.Subject = 'Chen' AND sg2.Grade = 'A'

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]





-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to