jdwilcock wrote:When I use more than 2 fields in the statement it doesn't work. Any ideas?
You are using an
Aggregate Function . . .
GROUP_CONCAT and therefore, each column in your result set
MUST be either:
- An Aggregate Function
- Included in the Group By clause
Also, a few of your column / field / table names are
NOT surrounded by double quotes, even though they are NOT UPPER CASE.
You wrote:
Code: Select all
SELECT
"Key",
"OrderNumber",
"OrderDate",
"OrderTime",
"IP",
"OrderID",
GROUP_CONCAT("Item" ) as "Item",
"Describe",
"OneTime",
"Color",
"Size",
"AddOn1"
FROM table1
GROUP BY OrderNumber;
Now, try this, just as an example:
Code: Select all
SELECT
-- "Key",
"OrderNumber",
-- "OrderDate",
-- "OrderTime",
-- "IP",
-- "OrderID",
GROUP_CONCAT("Item" ) as "Item",
-- "Describe",
-- "OneTime",
-- "Color",
-- "Size",
-- "AddOn1"
FROM "table1"
GROUP BY "OrderNumber";
Now, try this, just as another example:
Code: Select all
SELECT
-- "Key",
"OrderNumber",
-- "OrderDate",
-- "OrderTime",
-- "IP",
-- "OrderID",
GROUP_CONCAT(CONCAT_WS(' - ', "Item", "Describe", "Color", "Size")) as "Item",
-- "OneTime",
-- "AddOn1"
FROM "table1"
GROUP BY "OrderNumber";
Explanation:
- The above, for each UNIQUE "Order Number" the database back-end ( HSQL 2.3.? ) will use the Aggregate Function GROUP_CONCAT to return the "Item" separated by a comma.
- Since, I do NOT really know, what you want the result set to look like, I just commented count ( -- ) some of the columns.
- The second example, is using the HSQL 2.3 function, CONCAT_WS to concatenate the content of a few columns, each separated by text string ' - ' to comprise the GROUP_CONCAT column "Item" .
- If you want to include, in the GROUP_CONCAT aggregate function, using the CONCAT_WS function, a Date, Time, or TimeStamp column, you should use the HSQL function TO_CHAR to return the value as a string.
I hope this helps, please be sure to let me / us know.
Sliderule
Thanks to add
[Solved] in your
1st post Subject (edit button top right) if this issue has been resolved.