I am trying to select row which is not in table.
In brief, there are five tables student, cls, sec, sch, std_sch. Here, I want to select rows from std_sch which are not in sch
But LEFT JOIN with IS NULL is returning null result.
Table cls - lists of Class
id | ttl
===========
1 | One
2 | Two
Table sec - lists of section
id | ttl
===========
1 | A
2 | B
Table sch - lists of scholarship
id | ttl
===============
1 | First
2 | Second
3 | Third
Table student
id | ttl | cls | sec
===========================
1 | John| 1 | 1
2 | Paul| 1 | 0
Table sdt_sch - lists of scholarship assigned to student
id | s_id| sdt_sch
=======================
1 | 1 | 1
Mysql Code
SELECT
student.id AS sid,
student.ttl AS stdt,
cls.ttl AS cls,
sec.ttl AS sec,
GROUP_CONCAT(sch.ttl) AS sch
FROM
student
JOIN
cls ON cls.id=student.cls
LEFT JOIN
sec ON sec.id=student.sec
LEFT JOIN
std_sch ON std_sch.s_id = student.id
LEFT JOIN
sch ON sch.id = std_sch.sch_id
WHERE
cls.id = 1
AND
std_sch.sch_id IS NULL
GROUP BY
student.id
Expected Result should be as follow : because First Scholarship (sch - 1) is exists in table sdt_sch. But I am getting null results about this row
sid | stdt| cls | sec| sch
============================================
1 | John| One | A | Second,Third
2 | Paul| One | A | First,Second,Third
I have attached - SQL Fiddle also
sqlfiddleis exactly reverse to my requirement. In yoursqlfiddle, it is displaying the rows which has been already assigned to this student. But my expected result is to select rows which are not assigned to this student. It means which is not instd_sch(student_scholarship) table. Instd_schtable only one row 1 is assigned tostudent.id1, So in result It has to show everysch.idexcepting 1 for thisstudent.id.second,Thirdfor the student john, but it is showingFirstinsqlfiddlethat you provided. BecauseFirsthas been assigned already, So I need to escapeFirstid and show rest of the rows.