0

i have a problem, lets say i make a Select search through several tables and end up with this table: http://oi59.tinypic.com/2iict36.jpg

And i want it to look like that ( for further processing)

http://oi60.tinypic.com/2vcz0wm.jpg

i could use || operator, but the problem is that i dont know how many diffrent values will be in each subgroup, so i cant really hardcode a few || because sometimes i will need to merge 2 fields, and sometimes 4 etc. Is there any way to merge fields with specified range? or to implement FOR loop, or something similar?

im quite new to SQlite, so any help would be appreciated

1 Answers1

0

SQLite has the GROUP_CONCAT() aggregate function.

SELECT group,
    subgroup,
    GROUP_CONCAT(value) AS "value"
FROM MyTable
GROUP BY group, subgroup

If you need to control the order of values, you'll need to use a subquery like this.

Community
  • 1
  • 1
Bacon Bits
  • 30,782
  • 5
  • 59
  • 66
  • ok, thanks, that should work. but my case is a bit more complicated than the example showed. the "value" field comes from different table, and i use its id field to match it with correct group, and subgroup. if i just use this group_concat , is there a way to still provide some requirments (like value.id = group.id AND value.id = subgroup.id)? – Tymek Głowacki Nov 10 '14 at 15:04
  • @TymekGłowacki Sure. Just put the `GROUP BY` after the `WHERE` clause but before any `ORDER BY`. – Bacon Bits Nov 10 '14 at 15:20
  • Praise the Sun! it worked! thanks a lot! You just saved my ass, and are considered my new personal Jesus :D – Tymek Głowacki Nov 10 '14 at 15:39