Skip to content

Instantly share code, notes, and snippets.

@Chetan496
Created September 25, 2016 08:16
Show Gist options
  • Save Chetan496/ceb9c14ce9b53497e8071b637f869d59 to your computer and use it in GitHub Desktop.
Save Chetan496/ceb9c14ce9b53497e8071b637f869d59 to your computer and use it in GitHub Desktop.
SELECT id, instanceId, processModelId, GROUP_CONCAT(CONCAT_WS("=", variableName, oldValue)) AS OLDVALUE,
GROUP_CONCAT(CONCAT_WS("=", variableName, newValue)) AS NEWVALUE , parentVariableName FROM `Object_History`
GROUP BY instanceId, parentVariableName;
@Chetan496
Copy link
Author

This shows how to group the expanded individual fields of a CDT in a single row

@Chetan496
Copy link
Author

You will need to take care of the length of the Strings. The concatenation may produce strings which are very long. You need to set some limit especially in case of arrays - about how many variables you are going to edit etc.

@Chetan496
Copy link
Author

A better version:

SELECT id, instanceId, processModelId, GROUP_CONCAT(CONCAT_WS("=", variableName, oldValue) SEPARATOR ", ") AS OLDVALUE,
GROUP_CONCAT(CONCAT_WS("=", variableName, newValue) SEPARATOR ", ") AS NEWVALUE , parentVariableName FROM Object_History
GROUP BY instanceId, parentVariableName;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment