SQL Select Return Default Value If Null

前端 未结 5 1362
伪装坚强ぢ
伪装坚强ぢ 2021-01-01 10:20

Database: MS SQL 2008

SELECT Listing.Title, Listing.MLS, Pictures.PictureTH, Pictures.Picture, Listing.ID 
FROM Listing INNER JOIN Pictures          


        
5条回答
  •  说谎
    说谎 (楼主)
    2021-01-01 11:25

    Use left outer join instead of inner join

    Inner join will return results if and only if there is a result that satisfies the join.

    Left outer join will return results from the left side table, and if the join is satisfied also add results from the right side table..

    If you need to convert the null values returned from the non-satisfying joins, then use coalesce function like coalesce(Pictures.Picture, 'default.jpg')

提交回复
热议问题