Mysql
 sql >> Database >  >> RDS >> Mysql

MYSQL Left unisce A.table e b.table pur mantenendo a.table id

Usalo in questo modo:

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