MySQL COALESCE用于选择插入的两个结果集,而不是/or?

MySQL COALESCE用于选择插入的两个结果集,而不是/or?,mysql,coalesce,Mysql,Coalesce,所以我对下面的查询有一个问题。。因此,查询只选择comment.author\u id或stream.author\u id进行插入,而我需要它同时选择满足where条件的位置,以便为流项目author id和与目标流id关联的所有注释的author id插入通知。非常感谢所有帮助 INSERT INTO notification (text, type, target_id, sender_id, recipient_id, data, timestamp, is_unread

所以我对下面的查询有一个问题。。因此,查询只选择comment.author\u id或stream.author\u id进行插入,而我需要它同时选择满足where条件的位置,以便为流项目author id和与目标流id关联的所有注释的author id插入通知。非常感谢所有帮助

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'

我同意gbn。如果出于某种原因必须连接它们,可以使用concat()或concat_ws()函数

concat(col1,col2,…):

返回:

abc

浓缩液(分离器,col1,col2,…):

返回:

a、 b,c


你需要注意铸造类型的特殊情况。请参阅手册中的本节。

不应将两个字段都插入一个字段中。如果两者都需要,则有两个单独的列
select concat('a','b','c');
select concat_ws(',','a','b','c');