Ankit  Shukla

Ankit Shukla

  • NA
  • 681
  • 110.7k

join query with default value, if no match

Jul 31 2019 6:04 AM
Hello All,
 
Suppose  I have 2 tables:
 
Table1:
 
Status_CD  | Status 
---------------------------
1                 |  A
2                 | B 
 
 
Table2:
 
SNo   |   Status_CD
---------------------------
1       |   1
1       |   2
2       |   1
 
 
Need count of Status as per SNo And Output should be this:
 
SNo  |  Status  | Counts 
---------------------------------
1      |  A           | 1
1      | B            | 1
2      | A            | 1
2      | B            | 0 
 
How can I get this output (Row 4). If there is no matching then gives 0 by default?
 
Thanks in advance.

Answers (2)