How to join two tables in two fields, provided that the second field of the second table can sometimes be null (in this case, the join is needed only in the first field)? 1 table:

 поле1 | поле2 ------------ type1 | cat1 type1 | cat2 type1 | cat3 

2 table:

 поле1 | поле2 ------------- type1 | cat1 type1 | type1 | cat2 

Those. if field2 is not cat2 or cat1, then joining only by field1 (i.e., for all categories except 1 and 2, the same values) Result according to Chad's proposal

 поле1 | поле2 ------------ type1 | cat1 type1 | cat2 type1 | type1 | cat3 
  • one
    on (a.field1=b.field1 and (a.field2=b.field2 or b.field2 is null)) ? - Chad
  • one
    Can you add details to your question? As far as I understand, LEFT JOIN just suits you in this case. - Vadim Ovchinnikov
  • Chad, then 2 lines out for each join - Elena Katz
  • Show the result on THIS source data. - Akina
  • type1 | cat1 type1 | cat2 type1 | type1 | cat3 - Elena Katz

0