so I’m having a problem with this following query.. So, the query is only selecting either the comment.author_id OR the stream.author_id for insertion, whereas I need it to select both where it meets the where conditions so it inserts notifications for both a stream items author id, and the author id for all comments associated with the target stream id. All help is appreciated
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'
I agree with gbn. If for some reason you have to concatenate them you can use the concat() or concat_ws() function.
concat(col1,col2,…):
Returns:
concat_ws(separater,col1,col2,…):
Returns:
You need to watch out for special situations with casting types. Look at this section on String Functions in the manual.