0

I want to write an sqlite query in which a record will be displayed for example i have a contact table and account table i want to fetch a acount name and contact name from table i want to group_concat the contact name and it should not be repeated so i return a query:

select a.account_name, group_concat(DISTINCT c.contact_name) from account_table a join contact_table c on a.account_id = c.account_id;

this query execute perfectly know what i want to do is to get group_concat distinct name in asc order so i written the query :

 select a.account_name, group_concat(DISTINCT c.contact_name order by c.contact_name) from account_table a join contact_table c on a.account_id = c.account_id;

its giving me error at order by

10-25 10:29:25.601: E/SQLiteLog(2214): (1) near "order": syntax error

can any one tell me how to solve the error.

Neerav Shah
  • 713
  • 5
  • 18
  • 39
  • Possible duplicate of [Sqlite group\_concat ordering](https://stackoverflow.com/questions/1897352/sqlite-group-concat-ordering) – szmate1618 Jul 17 '19 at 13:19

1 Answers1

0

You can't use ORDER BY clause inside aggregate function call.

Try:

select a.account_name, group_concat(DISTINCT c.contact_name)
from account_table a
join contact_table c on a.account_id = c.account_id
order by c.contact_name;
LS_ᴅᴇᴠ
  • 10,823
  • 1
  • 23
  • 46