MySQL COALESCE alternative for selecting both result sets for an insert, not either / or? -
MySQL COALESCE alternative for selecting both result sets for an insert, not either / or? -
so i'm having problem next query.. so, query selecting either comment.author_id or stream.author_id insertion, whereas need select both meets conditions inserts notifications both stream items author id, , author id comments associated target stream id. help appreciated
insert 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' stream left bring together comment on comment.target_id = stream.id (comment.target_id = '$id' or stream.id = '$id') , comment.author_id != '$senderid'" , stream.author_id != '$senderid'
i agree gbn. if reason have concatenate them can utilize concat() or concat_ws() function.
concat(col1,col2,...):
select concat('a','b','c');
returns:
abc
concat_ws(separater,col1,col2,...):
select concat_ws(',','a','b','c');
returns:
a,b,c
you need watch out special situations casting types. @ section on string functions in manual.
mysql coalesce
Comments
Post a Comment