[Solved] Select preferred address if exists otherwise select ‘work’ address


This should do:

 SELECT * 
FROM   peopleaffiliation pa 
       LEFT OUTER JOIN addresses addr 
                    ON pa.addressid = addr.addressid 
       LEFT OUTER JOIN addresstypes addtyp 
                    ON addtyp.addresstypeid = addr.addresstypeid 
WHERE  (addr.preferredaddress = 1 )
        OR( COALESCE(addr.preferredaddress, 0) = 0 
           AND addtyp.addresstypeconst="Work" )

0

solved Select preferred address if exists otherwise select ‘work’ address