Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to return null values using SQL Left Join
    primarykey
    data
    text
    <p>Please look at this SQL Fiddle for the tables and what query I have tried:<br> <a href="http://sqlfiddle.com/#!2/4c7b2/1" rel="noreferrer">SQL Fiddle</a> </p> <p>So basically, I have two tables namely <strong>tbl_curriculum</strong> and <strong>tbl_enrolled_subjects</strong>. </p> <p><strong>tbl_curriculum</strong> contains all the subjects (subject_id) a student should take based on his course (course_id).<br> <strong>tbl_enrolled_subjects</strong> contains all the subjects the student has taken/enrolled based on <strong>tbl_curriculum</strong>. </p> <p>I want to check which subjects the student has taken and which is not, the query should return something like this: </p> <pre><code>Subject_id|Grade|Status 23 | 2 |Passed 24 | 2 |Passed 31 | 2 |Passed 50 | 2 |Passed 83 | 1 |Passed 27 |NULL |NULL 28 |NULL |NULL 29 |NULL |NULL </code></pre> <p>. . . And So On.</p> <p>Subject_ID with Grade and Status mean the student has already taken the subject. On the otherhand, NULL values indicates the the student has not taken those subjects yet.<br> I used this query: </p> <pre><code>SELECT a.subject_id, b.grade, b.status FROM tbl_curriculum a LEFT JOIN tbl_enrolled_subjects b ON a.course_id = b.course_id AND a.subject_id = b.subject_id WHERE b.student_id_no='05-0531'; </code></pre> <p>But I keep getting only the subjects the student has taken.</p> <pre><code>Subject_id|Grade|Status 23 | 2 |Passed 24 | 2 |Passed 31 | 2 |Passed 50 | 2 |Passed 83 | 1 |Passed </code></pre> <p>Am I missing something? Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload