Asif
Asif

Reputation: 77

How to get full emails list from db using group_concat

I am using the query below to fetch emails records from table.

but its not getting full email list from the table.

select group_concat(email) as email from table
$temp=$Db1->fetch_array($sql);
$elist['emails']=$temp[email];

It brings out only 50+- records , but i have 1400+ records in db for email.

Question: How to get complete emails from the db using group_concat i.e. comma seperated.

Upvotes: 2

Views: 201

Answers (2)

Saharsh Shah
Saharsh Shah

Reputation: 29051

You have to reset the default length of GROUP_CONCAT function by running below query then you have run your query.

System variable: group_concat_max_len

SET SESSION group_concat_max_len = 10000;
SELECT GROUP_CONCAT(email) AS email FROM TABLE;

You can reset its value globally or session wise. Update the length based on you usage.

Upvotes: 0

user149341
user149341

Reputation:

You can't. GROUP_CONCAT() has a maximum length of 1024 characters (by default), and you're hitting that limit. It's possible to raise that limit, but not indefinitely, so that's not a good solution.

You don't need GROUP_CONCAT() here, though. What you want to do is fetch one row for each email address, i.e.

SELECT email FROM table
...
while ($row = $db->fetch_array) {
    $emails[] = $row["email"];
}

Upvotes: 2

Related Questions