> Format your SQL nicely, here is a great tool to do that:
> http://www.dpriver.com/pp/sqlformat.htm

SELECT child.id                                AS id,
       MAX(pm.start),
       MAX(membership.start),
       MAX(Ifnull(pm.start, membership.start)) AS start
FROM   organisation child
       LEFT JOIN organisation pmorg
         ON child.parent_organisation_id = pmorg.id
       LEFT JOIN membership
         ON child.id = membership.organisation_id
       LEFT JOIN membership pm
         ON pmorg.id = pm.organisation_id
WHERE  child.id IN ( 1, 3 )
       AND /*just look at example records*/
       Coalesce(pm.start, membership.start) IS NOT NULL
       AND ( ( membership.active = 1
               AND membership.amount_paid > 0.00 )
              OR ( pm.active = 1
                   AND pm.amount_paid > 0.00 ) )
GROUP  BY child.id

> Post your question on http://stackoverflow.com/


ok: 
http://stackoverflow.com/questions/6619859/mysql-maxisnulldate-field-or-maxcoalescedate-field


Jochen

-- 
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]

Reply via email to