I'm having a funky problem combining two tables (really one table and a view). I want all values from the first table, with a count from a second table, if rows exist. If not, I want 0. It seems simple to me, but I'm just not getting it.crm_reasons:crm_reason_id complaint1 y2 n3 y4 y5 ncrm_ir_with_calldate:crm_reason_id crm_interaction_id date_called...2 100 2006-04-01 12:00:003 101 2006-04-02 12:00:005 101 2006-04-02 12:00:004 102 2006-04-03 12:00:003 103 2006-04-04 12:00:00...
TSQL:SELECT r.crm_reason_id, if(COUNT(ir.crm_reason_id) IS NOT NULL, COUNT(ir.crm_reason_id), 0) AS countFROM crm_reasons rLEFT OUTER JOIN crm_ir_with_calldate ir ON r.crm_reason_id = ir.crm_reason_idWHERE r.complaint = 'y'AND ir.date_called BETWEEN '2006-04-01' AND '2006-04-25 23:59:59'GROUP BY r.crm_reason_idORDER BY r.crm_reason_id
Should yield:crm_reason_id count1 03 24 1
But instead, I get:crm_reason_id count3 24 1
What did I do wrong?__________________________Thanks,CF