Skip to content
Advertisement

SQL Join : how to show the first table data even the 2nd table condition false

I want to keep show my first table data even the second table condition is false.

Table 1

Table 2

I expect data like this when I asking data for the date = ‘2019-02-18’ and ID = 1

Advertisement

Answer

Are you looking for a simple LEFT JOIN, as follows ?

The LEFT JOIN optionaly searches for record in table2 with the given date criteria. When no record match, t2.weight is NULL : COALESCE() picks up this situation, and returns 0 instead.

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