mysql eliminate responses under certain condition with join
Posted
by Dustin
on Stack Overflow
See other posts from Stack Overflow
or by Dustin
Published on 2010-05-29T13:26:05Z
Indexed on
2010/05/29
13:32 UTC
Read the original article
Hit count: 240
mysql-query
Forgive me if this is an easy question. I teach classes and want to be able to select those students who have taken one class, but not another class. I have two tables: lessons_slots which is the table for every class such as:
--------------------
-ID name slots-
-1 basics 10 -
-2 advanced 10 -
-3 basics 10 -
---------------------
The other table is class_roll, which holds enrollment info, such as:
--------------------
-sID classid firstname lastname-
-1 1 Jo Schmo
-2 1 Person Two
...
-13 2 Jo Schmo
---------------------
What I want to do, I select everyone who has not had the advanced class (for example). I've tried doing
SELECT *
FROM lessons_slots
LEFT JOIN class_roll
ON lessons_slots.ID = class_roll.classid
WHERE lessons_slots.name != 'advanced'
But that doesn't work. Any ideas?
© Stack Overflow or respective owner