Question : MySQL Right Outer Join

Hey Guys,

I'm trying to display a number of totals using a multifunction query:

SELECT u.USER_FNAME, u.USER_LNAME, COUNT(DISTINCT s1.SSA_FORM_ID) ssa_pro, COUNT(DISTINCT s2.SSA_FORM_ID) ssa_del, COUNT(DISTINCT i1.INQUIRY_FORM_ID) inq_pro
FROM tbl_USERS u, tbl_SSA_FORM_STATUS s1, tbl_SSA_FORM_STATUS s2, tbl_INQUIRY_FORM_STATUS i1
WHERE s1.USER_ID = u.USER_ID
AND s1.FORM_STATUS = 'C'      
AND s2.USER_ID = u.USER_ID
AND s2.FORM_STATUS = 'D'
AND i1.USER_ID = u.USER_ID
AND i1.FORM_STATUS = 'C'
AND u.USER_TYPE = 1
GROUP BY u.USERNAME
ORDER BY u.USER_LNAME ASC;

The problem is, one of the count functions currently returns 0 and doesn't display, but I still want it to be displayed.
I tried to do an outer join for each column, but I couldn't quite get the syntax.

Can someone help?
 

Answer : MySQL Right Outer Join

try this

SELECT u.USER_FNAME, u.USER_LNAME
      , COUNT(DISTINCT case s1.form_status when 'C' then s1.SSA_FORM_ID else null end) ssa_pro
      , COUNT(DISTINCT case s1.form_status when 'D' then s1.SSA_FORM_ID else null end) ssa_del
      , COUNT(DISTINCT i1.INQUIRY_FORM_ID) inq_pro
FROM tbl_USERS u
left outer join tbl_SSA_FORM_STATUS as s1
on u.user_id=s1.user_id

left outer join (select inquiry_form_id,user_id from tbl_INQUIRY_FORM_STATUS
where form_status='C') as i1
on u.user_id=i1.user_id
WHERE u.USER_TYPE = 1
GROUP BY u.USER_lnAME,u.user_fname
ORDER BY u.USER_LNAME ASC,u.user_fname
Random Solutions  
 
programming4us programming4us