Doubt with a MYSQL query

2

As the title says it is a doubt because I'm not sure it can be done, but hey, there it goes:

Let's say that I make a join of two tables, one has ads (spots) and the other ad units, the query looks like this:

SELECT Blocs.Numbloc, Spots.Nom FROM Blocs, Spots WHERE Blocs.Spot=Spots.ID

And the result is the following:

So, my question is this:

Is there any way (with a SQL query) that you return all the names of each "block number" in a row, adding a ',' for each name?

Example:

Now it's like this:

Numbloc |    Nom
_______     _____

6       |    Non Massa Non Company

6       |    Arcu LLP

6       |    Augue Corporation

And I would like it to be like this:

Numbloc |    Nom
_______     _____

6       |    Non Massa Non Company, Arcu LLP, Augue Corporation

Greetings and thank you very much

    
asked by Tennosuke 27.04.2016 в 19:54
source

1 answer

4

You have to use the function GROUP_CONCAT

SELECT Blocs.Numbloc, GROUP_CONCAT(Spots.Nom)
  FROM Blocs, Spots 
 WHERE Blocs.Spot=Spots.ID
GROUP BY Blocs.Numbloc

link

More info on GROUP_CONCAT

    
answered by 27.04.2016 / 20:12
source