1

I recently discovered the limitations of GROUP_CONCAT. I have a query with 482 results. I need to get a CSV of all 482 IDs. When I run GROUP_CONCAT, it can only get 147 at a time (with ,10) left over:

SELECT GROUP_CONCAT(id) 
  FROM account 
 WHERE parent_account_id = 707070 
   AND id != parent_account_id;

I've tried using LIMIT:

SELECT GROUP_CONCAT(id) 
  FROM account 
 WHERE parent_account_id = 707070 
   AND id != parent_account_id 
 LIMIT 0, 100;

But this doesn't work when I try to get the next 100:

SELECT GROUP_CONCAT(id) 
  FROM account 
 WHERE parent_account_id = 707070 
   AND id != parent_account_id 
 LIMIT 100, 100;

Are there any other SQL tricks for getting a long CSV without me having to export the results to a file and then use regex to replace newlines with commas?

Saagar Elias Jacky
  • 2,684
  • 2
  • 14
  • 28
NobleUplift
  • 5,631
  • 8
  • 45
  • 87
  • http://stackoverflow.com/search?q=mysql+group_concat_max_len There's a session variable `group_concat_max_len` – Michael Berkowski Apr 08 '15 at 21:01
  • Ah, sorry for the duplicate, but when I typed in my question I did not get that question as a suggestion. I used `SET SESSION group_concat_max_len=65535;` as a solution. – NobleUplift Apr 08 '15 at 21:49
  • 1
    No problem - the magic search term was "truncate" and I had to search 3 times to find it, though I knew it was there. – Michael Berkowski Apr 08 '15 at 22:10

0 Answers0