SQLite Forum

select * from t; -- but don't want virtual columns
Login
group_concat will will work in "visitation order".  The order by clause imposes "presentation order" of the results.

```
sqlite> create table x(a,b,c,d,e,f);
sqlite> select group_concat(name, ', ') from pragma_table_info where arg='x' order by cid asc;
┌──────────────────────────┐
│ group_concat(name, ', ') │
├──────────────────────────┤
│ a, b, c, d, e, f         │
└──────────────────────────┘
sqlite> select group_concat(name, ', ') from pragma_table_info where arg='x' order by cid desc;
┌──────────────────────────┐
│ group_concat(name, ', ') │
├──────────────────────────┤
│ a, b, c, d, e, f         │
└──────────────────────────┘
sqlite> select group_concat(name, ', ') from (select name from pragma_table_info where arg='x' order by cid asc);
┌──────────────────────────┐
│ group_concat(name, ', ') │
├──────────────────────────┤
│ a, b, c, d, e, f         │
└──────────────────────────┘
sqlite> select group_concat(name, ', ') from (select name from pragma_table_info where arg='x' order by cid desc);
┌──────────────────────────┐
│ group_concat(name, ', ') │
├──────────────────────────┤
│ f, e, d, c, b, a         │
└──────────────────────────┘
```

So applying "presentation order" does not affect "visitation order" to the members of the group unless the "visitation" is the result of applying "presentation order" to the rows being visited.

Without the subselect being ordered the result is one row and "cid" has one value per group (it is a bare column of an aggregate even though it is not output in the select list, it must still be computed as if it were).  Hence the one row generated by the select will be the same notwithstanding any order by.

However, in the subselect the "presentation order" of the rows of names is affected by the order by so the "visitation order" of the rows in the aggregate will be that "presentation order".

Of course, if you want the results in "order by cid" then you need do nothing since that is the "presentation order" of the virtual table anyway -- but that might be viewed as an "implementation detail" although I should think that it is unlikely to change.