1.在沒有設置默認值的情況下:
復制代碼 代碼如下:
SELECT userinfo.id, user_name, role, adm_regionid, region_name , create_time
FROM userinfo
LEFT JOIN region ON userinfo.adm_regionid = region.id
結果:
設置顯示默認值:
復制代碼 代碼如下:
SELECT userinfo.id, user_name, role, adm_regionid, IFNULL(region_name,0) as region_name, create_time
FROM userinfo
LEFT JOIN region ON userinfo.adm_regionid = region.id
即:如果region_name一列的值為空,則顯示為0,結果為:
本文來自:http://blog.csdn.net/xyw_blog/article/details/26250331