當我執行以下查詢: -Mysql的設置默認值,如果該項不存在
SELECT users.id, users.username, users.last_login,
profile_pictures.pic_resized, profile_pictures.pic_blurred,
user_profile.date_of_birth, user_profile.u_country,
matches.total_score AS score,
favorites.id AS is_favorite,
relationships.id AS is_match,
profile_visitors.id AS is_profile_viewer,
block_chat.id AS is_blocked
FROM users
INNER JOIN user_profile ON users.id = user_profile.user_id
LEFT JOIN profile_pictures ON users.id = profile_pictures.user_id
LEFT JOIN match_collections ON users.id = match_collections.user_id AND match_collections.status='valid'
LEFT JOIN matches ON matches.collection_id = match_collections.id AND match_id = 44700
LEFT JOIN favorites ON favorites.subject_id = 11354 AND favorites.object_id = 44700
LEFT JOIN relationships ON relationships.user_id = 11354 AND relationships.friend_id = 44700
LEFT JOIN profile_visitors ON profile_visitors.viewed_id = 11354 AND profile_visitors.viewer_id = 44700
LEFT JOIN block_chat ON block_chat.subject_id = 11354 AND block_chat.object_id = 44700
WHERE users.id = 11354
結果顯示: 其中is_favorite和is_match爲null這是指有用戶44700沒有條目在那些表格中。
現在的問題是:如何設置一個默認值,如-1
而不是NULL
?
順便說一下,它不是'isnull'而是'ifnull'。 MSSQL中存在'isnull'。 – Rahul
isnull()不能正常工作? – KrazzyNefarious