Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

MYSQL Left join A.table e b.table mantendo o id de a.table


Use assim:
SELECT 
    *,
    COALESCE(b.customer_id, 0) AS customer_id
FROM sales_customer a 
LEFT JOIN sales_contact b ON a.customer_id = b.customer_id
ORDER BY 
    CASE WHEN company_name = '' THEN lname ELSE company_name END ASC