How to show the same value in one row using group by










-2















I need some help.

I want to show the same value in one row from mysql using PHP.



I have table



ID Name
------------------
01 Juan
01 Ben
02 Pedro
02 Jose


Expect Ouput



ID NAME
--------------------
01 Juan, Ben
02 Pedro, Jose


How to do it?










share|improve this question
























  • have you at least made an attempt?

    – user10226920
    Nov 14 '18 at 6:12







  • 1





    Before posting a question, you should have done the proper research and made attempts to solve your issue yourself. Then, if you get stuck on something specific, come back and show us your attempt. Please read How much research effort is expected of Stack Overflow users?, How to create a Minimal, Complete, and Verifiable example and also How do I ask a good question?

    – Magnus Eriksson
    Nov 14 '18 at 6:16















-2















I need some help.

I want to show the same value in one row from mysql using PHP.



I have table



ID Name
------------------
01 Juan
01 Ben
02 Pedro
02 Jose


Expect Ouput



ID NAME
--------------------
01 Juan, Ben
02 Pedro, Jose


How to do it?










share|improve this question
























  • have you at least made an attempt?

    – user10226920
    Nov 14 '18 at 6:12







  • 1





    Before posting a question, you should have done the proper research and made attempts to solve your issue yourself. Then, if you get stuck on something specific, come back and show us your attempt. Please read How much research effort is expected of Stack Overflow users?, How to create a Minimal, Complete, and Verifiable example and also How do I ask a good question?

    – Magnus Eriksson
    Nov 14 '18 at 6:16













-2












-2








-2








I need some help.

I want to show the same value in one row from mysql using PHP.



I have table



ID Name
------------------
01 Juan
01 Ben
02 Pedro
02 Jose


Expect Ouput



ID NAME
--------------------
01 Juan, Ben
02 Pedro, Jose


How to do it?










share|improve this question
















I need some help.

I want to show the same value in one row from mysql using PHP.



I have table



ID Name
------------------
01 Juan
01 Ben
02 Pedro
02 Jose


Expect Ouput



ID NAME
--------------------
01 Juan, Ben
02 Pedro, Jose


How to do it?







php mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 6:16









Magnus Eriksson

7,19141327




7,19141327










asked Nov 14 '18 at 6:10









Richard FloresRichard Flores

22




22












  • have you at least made an attempt?

    – user10226920
    Nov 14 '18 at 6:12







  • 1





    Before posting a question, you should have done the proper research and made attempts to solve your issue yourself. Then, if you get stuck on something specific, come back and show us your attempt. Please read How much research effort is expected of Stack Overflow users?, How to create a Minimal, Complete, and Verifiable example and also How do I ask a good question?

    – Magnus Eriksson
    Nov 14 '18 at 6:16

















  • have you at least made an attempt?

    – user10226920
    Nov 14 '18 at 6:12







  • 1





    Before posting a question, you should have done the proper research and made attempts to solve your issue yourself. Then, if you get stuck on something specific, come back and show us your attempt. Please read How much research effort is expected of Stack Overflow users?, How to create a Minimal, Complete, and Verifiable example and also How do I ask a good question?

    – Magnus Eriksson
    Nov 14 '18 at 6:16
















have you at least made an attempt?

– user10226920
Nov 14 '18 at 6:12






have you at least made an attempt?

– user10226920
Nov 14 '18 at 6:12





1




1





Before posting a question, you should have done the proper research and made attempts to solve your issue yourself. Then, if you get stuck on something specific, come back and show us your attempt. Please read How much research effort is expected of Stack Overflow users?, How to create a Minimal, Complete, and Verifiable example and also How do I ask a good question?

– Magnus Eriksson
Nov 14 '18 at 6:16





Before posting a question, you should have done the proper research and made attempts to solve your issue yourself. Then, if you get stuck on something specific, come back and show us your attempt. Please read How much research effort is expected of Stack Overflow users?, How to create a Minimal, Complete, and Verifiable example and also How do I ask a good question?

– Magnus Eriksson
Nov 14 '18 at 6:16












1 Answer
1






active

oldest

votes


















1














You can group by the column you want to be unique and use group_concat() to get a list of the names for each group



select id, group_concat(name separator ', ') as names
from your_table
group by id





share|improve this answer




















  • 1





    In my opinion, low quality questions that contains absolutely zero attempts shouldn't be answered. The OP should at least show some effort of trying to solve the issue them selves before asking.

    – Magnus Eriksson
    Nov 14 '18 at 6:18












  • Thanks man, but one thing in using group_cat() how to change the separator the comma and add some space because the output it is one word

    – Richard Flores
    Nov 14 '18 at 6:26












  • Thanks @juergen d you save my time :)

    – Richard Flores
    Nov 14 '18 at 6:41










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294117%2fhow-to-show-the-same-value-in-one-row-using-group-by%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can group by the column you want to be unique and use group_concat() to get a list of the names for each group



select id, group_concat(name separator ', ') as names
from your_table
group by id





share|improve this answer




















  • 1





    In my opinion, low quality questions that contains absolutely zero attempts shouldn't be answered. The OP should at least show some effort of trying to solve the issue them selves before asking.

    – Magnus Eriksson
    Nov 14 '18 at 6:18












  • Thanks man, but one thing in using group_cat() how to change the separator the comma and add some space because the output it is one word

    – Richard Flores
    Nov 14 '18 at 6:26












  • Thanks @juergen d you save my time :)

    – Richard Flores
    Nov 14 '18 at 6:41















1














You can group by the column you want to be unique and use group_concat() to get a list of the names for each group



select id, group_concat(name separator ', ') as names
from your_table
group by id





share|improve this answer




















  • 1





    In my opinion, low quality questions that contains absolutely zero attempts shouldn't be answered. The OP should at least show some effort of trying to solve the issue them selves before asking.

    – Magnus Eriksson
    Nov 14 '18 at 6:18












  • Thanks man, but one thing in using group_cat() how to change the separator the comma and add some space because the output it is one word

    – Richard Flores
    Nov 14 '18 at 6:26












  • Thanks @juergen d you save my time :)

    – Richard Flores
    Nov 14 '18 at 6:41













1












1








1







You can group by the column you want to be unique and use group_concat() to get a list of the names for each group



select id, group_concat(name separator ', ') as names
from your_table
group by id





share|improve this answer















You can group by the column you want to be unique and use group_concat() to get a list of the names for each group



select id, group_concat(name separator ', ') as names
from your_table
group by id






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 6:38

























answered Nov 14 '18 at 6:15









juergen djuergen d

160k24202260




160k24202260







  • 1





    In my opinion, low quality questions that contains absolutely zero attempts shouldn't be answered. The OP should at least show some effort of trying to solve the issue them selves before asking.

    – Magnus Eriksson
    Nov 14 '18 at 6:18












  • Thanks man, but one thing in using group_cat() how to change the separator the comma and add some space because the output it is one word

    – Richard Flores
    Nov 14 '18 at 6:26












  • Thanks @juergen d you save my time :)

    – Richard Flores
    Nov 14 '18 at 6:41












  • 1





    In my opinion, low quality questions that contains absolutely zero attempts shouldn't be answered. The OP should at least show some effort of trying to solve the issue them selves before asking.

    – Magnus Eriksson
    Nov 14 '18 at 6:18












  • Thanks man, but one thing in using group_cat() how to change the separator the comma and add some space because the output it is one word

    – Richard Flores
    Nov 14 '18 at 6:26












  • Thanks @juergen d you save my time :)

    – Richard Flores
    Nov 14 '18 at 6:41







1




1





In my opinion, low quality questions that contains absolutely zero attempts shouldn't be answered. The OP should at least show some effort of trying to solve the issue them selves before asking.

– Magnus Eriksson
Nov 14 '18 at 6:18






In my opinion, low quality questions that contains absolutely zero attempts shouldn't be answered. The OP should at least show some effort of trying to solve the issue them selves before asking.

– Magnus Eriksson
Nov 14 '18 at 6:18














Thanks man, but one thing in using group_cat() how to change the separator the comma and add some space because the output it is one word

– Richard Flores
Nov 14 '18 at 6:26






Thanks man, but one thing in using group_cat() how to change the separator the comma and add some space because the output it is one word

– Richard Flores
Nov 14 '18 at 6:26














Thanks @juergen d you save my time :)

– Richard Flores
Nov 14 '18 at 6:41





Thanks @juergen d you save my time :)

– Richard Flores
Nov 14 '18 at 6:41



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294117%2fhow-to-show-the-same-value-in-one-row-using-group-by%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto