Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8409355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:53:10+00:00 2026-06-09T23:53:10+00:00

I am trying to use two GROUP_CONCATs in the same SQL statement. I have

  • 0

I am trying to use two GROUP_CONCATs in the same SQL statement.

I have the following code:

try
{
$sql = 'SELECT player.id, player.name AS name, GROUP_CONCAT(previousclubs.name) 
        previousclubs, satscore, gpa, GROUP_CONCAT(link) link
            FROM player INNER JOIN playerpreviousclubs
                ON player.id = playerid
            INNER JOIN previousclubs
                    ON previousclubid = previousclubs.id
            INNER JOIN links
                ON links.playerid = player.id
            GROUP BY player.id';

$result = $pdo->query($sql);
}
catch (PDOException $e)
{
$error = 'Error fetching details: ' . $e->getMessage();
include 'error.html.php';
exit();
}

foreach ($result as $row)
{
$names[] = array(
                'id' => $row['id'], 
                'name' => $row['name'],
                'previousclubs' => $row['previousclubs'],
                'links' => $row['link']
                );
}
include 'profiles.html.php';

If a player has say three previous clubs and one link, then instead of displaying like this:

Name: John Smith

Previous Clubs: Arsenal, Reading, QPR

Links: http://www.bbc.co.uk

IT DISPLAYS LIKE THIS:

Name: John Smith

Previous Clubs: Arsenal, Reading, QPR

Links: http://www.bbc.co.uk, http://www.bbc.co.uk, http://www.bbc.co.uk

WORSE STILL IF YOU HAVE MULTIPLE LINKS (TWO LINKS ARE USED BELOW) YOU GET THIS:

Name: John Smith

Previous Clubs: Arsenal, Arsenal, Reading, Reading, QPR, QPR

Links: http://www.bbc.co.uk, http://www.football.com, http://www.bbc.co.uk, http://www.football.com, http://www.bbc.co.uk, http://www.football.com

Can someone please provide some guidance on what is going on here and how to rectify it.

The first GROUP_CONCAT on previousclubs works fine by itself but when the second GROUP_CONCAT for links is thrown in the mix, the issues mentioned above are occuring.

Thanks for your time and help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:53:12+00:00Added an answer on June 9, 2026 at 11:53 pm

    The problem is not GROUP_CONCAT, it is the arguments.

    Your second group concat should be:

    GROUP_CONCAT(distinct link) link 
    

    You can also control the ordering (in case you want most recent first, for instance). Check out the help page at http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to use lexer rules having same starting? I am trying to use two
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I'm actualilly trying tu use this nice widget : http://quasipartikel.at/multiselect_next/ I have two of
I'm trying to use two listviews (that are on same page - wpf) to
I am trying use an if statement and TWO .addClass background-color variables based on
I am trying to use two sounds when I button is pushed: one sound
I'm beginning python and I'm trying to use a two-dimensional list, that I initially
I'm trying to use the DSACryptoServiceProvider class with C# to create two DLLs: one
I'm trying to use Unix cut to remove the first two fields per line.
I am trying to use 'get_posts' to pick up posts that are in two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.