A 表user_id phone 1 1 2 2
B表user_id mail 1 1
想连表得到C,没有找到相同user_id的默认为0
C表user_id phone mail 1 1 1 2 2 0
mysql语句怎么写?
业精于勤,荒于嬉;行成于思,毁于随。
select A.user_id as user_id,A.phone as phone,coalesce(B.mail,0) as mailfrom A left join B on A.user_id=B.user_id
select A.user_id as user_id,A.phone as phone,coalesce(B.mail,0) as mail
from A left join B on A.user_id=B.user_id