Mysql Left Join Null Result

前端 未结 4 924
慢半拍i
慢半拍i 2020-12-30 02:52

I have this query

SELECT articles.*, 
       users.username AS `user` 
 FROM `articles` 
LEFT JOIN `users` ON articles.user_id = users.id 
 ORDER BY articles         


        
4条回答
  •  悲哀的现实
    2020-12-30 03:19

    You can use the IFNULL function:

    SELECT articles.*, IFNULL(users.username, 'User Not Found') AS `user`
    FROM `articles` LEFT JOIN `users` ON articles.user_id = users.id
    ORDER BY articles.timestamp 
    

提交回复
热议问题