SQL LEFT JOIN return 0 rather than NULL

Karl picture Karl · Jun 24, 2009 · Viewed 59.8k times · Source

I want to join two tables, with the number of records for each type being counted. If there are no records of that type in the left table I want a 0 to be returned, not a null.

How can I do this?

Answer

cjk picture cjk · Jun 24, 2009

Use:

ISNULL(count(*), 0)