Skip to content
Advertisement

Join tables to display null if right side table doesnt have data

I have a feedback_ques, feedback_ans table as follows:

I want to join the tables as follows:

This gives me all the fields. I want the query to return null for answers if they arent found in the answers table. For example member_id 20 doesnt have answers, so i would want the table to display null values as below for this query.

Updated: As suggested im using leftOuter join as follows:

But this query is not working when delete_date is !=null. That row is still returned by the query. From above quest 4 should not be returned since delete_date != null. Can you please help.

Advertisement

Answer

These old-shool, implicit joins, make it uneasy to express what you want. Here, the condition a.member_id = 20 in the where clause filters out unmatched rows.

This is just one of the reasons while explicit, standard joins should always be used. Consider a left join, where all conditions on the left table are placed in the on clause:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement