Split two rows into two columns
You can use a conditional aggregate:

select m.id, 
       t.name, 
       count(case when m.action = 0 then m.id end) as action1,
       count(case when m.action = 1 then m.id end) as action2
from table1 m
  left table2 t ON (m.id = t.id)
where m.status &lt;&gt; '2'
group by m.id, t.name;


In the upcoming 9.4 release the count(case(...)) could be written a bit shorter using the new "filtered" aggregate: count(id) filter (when m.action = 0)