Mysql joining 2 tables (default values)

Hello…

I came to situation where I have to join 2 tables on some other table:

some_table:
id
domain

table domains:
id
domaintype_id
domain

table domaintypes:
id
type

This is how I join:

domains ON some_table.domain = domains.domain
domaintypes ON domaintype.id = domains.domaintype_id

Now it happens that sometimes there is no domain for some_table row (so the domaintype will be NULL) and I want to be able to set this column default value 0 (when that happens)…

How is it possible to do that?

Many thanks in advance!


select coalesce(domain_id,0), ...
  from some_table
  left join domains on some_table.domain = domains.domain
  left join domaintypes on domaintype.id = domains.domaintype_id