I have a situation in my sql statement. In this sql statement, I joined 3 tables together (Application_Detail, Teacher_Detail, and Class_Detail), and than I used WHERE
to filter my table to find out how many teacher used this application, I found the following result.
As you can see in the 1st record, both teacher related and class related field are null. I am wondering is there a way to filter out the 1st record and only show the 2,3,4 record? because I want to only want to show the record if there are some value in teacherId, teacherName, class, or grade column.
teacherId teacherName applicationName class grade
1. NULL NULL Excel NULL NULL
2. 5 NULL Excel NULL NULL
3. NULL NULL Excel A 6
4 NULL NULL Excel B 2
Here is my SQL command
SELECT
td.teacherId,
teacherName,
applicationName,
class,
grade
FROM
[AppUser_Detail] as aud
LEFT OUTER JOIN [Teacher_Detail] as td ON aud.teacherId = td.teacherId
LEFT OUTER JOIN [Application_Detail] as ad ON aud.applicationId = ad.applicationId
LEFT OUTER JOIN [Class_Detail] as cd ON aud.classId = cd.classId
WHERE
aud.applicationId = 6 //I filter if my application Id is 6
Try this:
SELECT
td.teacherId,
teacherName,
applicationName,
class,
grade
FROM
[AppUser_Detail] as aud
LEFT OUTER JOIN [Teacher_Detail] as td ON aud.teacherId = td.teacherId
LEFT OUTER JOIN [Application_Detail] as ad ON aud.applicationId = ad.applicationId
LEFT OUTER JOIN [Class_Detail] as cd ON aud.classId = cd.classId
WHERE
td.teacherId is not null OR class is not null OR grade is not null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With