I’ve been pulling my hair out for two days trying to put a MySQL query together to pull some data together. This is beyond my level of experience with SQL, however.
The following query pulls the data that I need, but I need to format it differently so I can use it.
SELECT b.key, a.author, a.comment FROM action a, issue b
WHERE a.issueid=b.id AND a.actiontype='comment';
This produces output like so:
1 | joe | comment 3
3 | sally | comment 2
1 | sam | comment 2
2 | julie | comment 2
1 | bill | comment 1
3 | joe | comment 1
2 | sam | comment 1
b.key is unique and can contain 0-∞ a.comment. There is a 1-1 relationship with the a.author and a.comment and I must maintain the original association. The output seems to be in ascending order based on the date of a.comment.
I would like to do get the data into the following format (CSV,) merging the a.author and a.comment results into a single column:
"1", "bill - comment 1", "sam - comment 2", "joe - comment 1"
"2", "julie - comment 1", "sam - comment 2"
"3", "joe - comment 1", "sally - comment 2"
I played around with several combinations of GROUP_CONCAT and ORDER and also messed with subqueries a bit based on this post and can’t seem to get it formatted the way I need. Additionally, it seems like the order of the comment column changes. I need to maintain the original (oldest to newest) order, but my original query above produces results in newest to oldest order. If the delimiters pose a problem, I can certainly do some post processing with perl or awk search & replace on the results. Any help is greatly appreciated!
How about
with some post processing to split based on the pipe character. If you get truncation issues you may need to increase the value of group_concat_max_len.