Thanks first.
I have this right join worked fine, but when I try to change it into a left join I got an error.
The question is to get all information about the students from table Student who has higher score in class1 than class2 from a score-student table called SC.
Student(SId,Sname,Sage,Ssex)
SC(SId,CId,Score)
Here is my RIGHT JOIN:
SELECT * FROM Student RIGHT JOIN (
SELECT t1.SId, class1, class2 FROM
(SELECT SId, score as class1 FROM sc WHERE sc.CId = '01')AS t1,
(SELECT SId, score AS class2 FROM sc WHERE sc.CId = '02')AS t2
WHERE t1.SId = t2.SId
AND t1.class1 > t2.class2
)r
ON Student.SId = r.SId;
And then I tried something like:
SELECT t1.SId, class1, class2, Student.* FROM
(SELECT SId, score as class1 FROM sc WHERE sc.CId = '01')AS t1,
(SELECT SId, score AS class2 FROM sc WHERE sc.CId = '02')AS t2
WHERE t1.SId = t2.SId
AND t1.class1 > t2.class2
)r
LEFT JOIN Student
ON Student.SId = r.SId;
but it didn`t work.
I am pretty new with SQL, wish you could explain a little bit.
I am using MySQL5.7