0
因此,我遇到了以下查詢的問題。所以,查詢只選擇了comment.author_id或者stream.author_id進行插入,而我需要它來選擇符合where條件的地方,所以它爲流項作者ID和與目標流ID相關聯的所有評論的作者ID插入通知。所有幫助表示讚賞MySQL COALESCE替代選擇插入的兩個結果集,而不是/或?
INSERT INTO notification
(text, type, target_id, sender_id, recipient_id, data, timestamp, is_unread)
SELECT DISTINCT '$text', 'comment', '$id', '$senderId',
COALESCE(comment.author_id, stream.author_id),
'$dataArray','$timestamp', '1'
FROM stream
LEFT JOIN comment ON comment.target_id = stream.id
WHERE (comment.target_id = '$id' OR stream.id = '$id')
AND comment.author_id != '$senderId'"
AND stream.author_id != '$senderId'
你不應該插入到一個字段。如果你需要兩個,有2個獨立的列 – gbn