to get data from all 3 tables togehter this will work (but you will have to select the fields and add the where clause:
This will get ALL results from all 3 tables (and ones that are blank as well).
you can reference each field from each table by adding the "alias" to the field name.
So dp.numphds or mj.sid as examples.
Main Topics
Browse All Topics





by: racekPosted on 2009-04-17 at 12:19:32ID: 24171116
SELECT dname, count(*) students
FROM dept d
JOIN major m on d.dname = m.dname
JOIN (SELECT sid, SUM(IF(dname = 'Mathematics',1,0)) as mathstd
FROM ENROLL
GROUP BY 1 HAVING mathstd = 0) x
on x.sid = m.sid
GROUP BY 1;