SELECT CASE WHEN a.id='1002' THEN 1WHEN b.tel='1002' THEN 2 ENDAS flagFROM A LEFT JOIN BON 1=1LIMIT 1