mercredi 18 février 2015

Select rows that have two different values in same column

I would like to select all students that have been passed the semester 1 and 4, with my query it shows only one row by student witch I was expect two.



SELECT Student.mat_stud, fname, lname, dbirth, materials_notes, semester FROM Student, Notes
WHERE Notes.mat_stud = Student.mat_stud AND fails_status = 1 AND Notes.mat_div = 1 AND semester IN(1 , 4) AND Notes.level = 1
AND school_year = 2015 Group By Notes.mat_stud Having count(fname) = 2 Order By Notes.mat_stud


My database tables looks like this:



Student
-------------------------
mat_stud fname lname
-------------------------
142-3698 fname name
142-3699 fname name
142-3701 fname name
142-3698 fname name
142-3700 fname name
142-3700 fname name



Notes
---------------------------------------------------------------
mat_stud materials_notes semester level school_year
---------------------------------------------------------------
142-3698 1 1 2015
142-3699 1 1 2015
142-3701 1 1 2015
142-3698 4 1 2015
142-3700 1 1 2015
142-3700 4 1 2015


Expected result:



mat_stud fname lname materials_notes semester
142-3698 fname name 1
142-3698 fname name 4
142-3700 fname name 1
142-3700 fname name 4

Aucun commentaire:

Enregistrer un commentaire