SQL join multiple values from column into one cell?

GROUP BY MemberName and GROUP_CONCAT(FruitName). For example SELECT MemberId, MemberName, GROUP_CONCAT(FruitName) FROM a LEFT JOIN be ON a. MemberName = b.

MemberName GROUP BY a.MemberName.

GROUP BY MemberName and GROUP_CONCAT(FruitName). For example, SELECT MemberId, MemberName, GROUP_CONCAT(FruitName) FROM a LEFT JOIN be ON a. MemberName = b.

MemberName GROUP BY a.MemberName.

Hmm, tried this out and got an error that said that MemberName is an ambiguous field so I changed SELECT MemberID, MemberName to SELECT MemberID, a. MemberName and my out put looked like this: MemberID MemberName GROUP_CONCAT(FruitName) 1 Al BLOB - 3 B I will start a new question as Google is fruitless (no pun intended). Thanks!

– Adam Jul 20 '09 at 14:33.

Given that you're using mySQL, I believe the group_concat function will do exactly what you're looking for: dev.mysql.com/doc/refman/5.0/en/group-by....

Ah, nice to see I was wrong :-) – Brimstedt Jul 20 '09 at 5:53.

SELECT MemberID, MemberName, GROUP_CONCAT(FruitName SEPARATOR ',') FROM a LEFT JOIN be ON a. MemberName = b. MemberName GROUP BY MemberID, MemberName.

Had the exact same problem as below – Adam Jul 20 '09 at 11:49.

One way is to loop and build the output in PHP (or whatever language yo are using). Either concatenate the fruits when fetching the rows from db, or when presenting it to the user. Id suggest the latter, since it's more of a view-logic issue than anything else.

If you want to do it in SQL you'll either have to create your own (I do not belive MySQL has it built in, but I might be wrong) aggregate function to concatenate strings. It is not so trivial. If you are fetching only one member, you can also do it in SQL by using a variable, Im uncertaing about the exact MySQL syntax, but for MSSQL it would be something like: DECLARE @frutis VARCHAR(MAX) SELECT @fruits = ISNULL(@fruits + ', ' + FruitName, FruitName) FROM ... SELECT @fruits.

There are a ton of sql join q's already but I didn't see my answer so here goes . I am working with WPDB (Wordpress database)/EZSql/MySQL 5.0. Trying to achieve the 'simple' desired output below has not proven to be easy.

MemberID comes from table a, MemberName comes from table a and table b, and FruitName comes from table b. I assume I should try to query/join the two tables in a different manner though it may be possible to get creative in printing the columns. I found this discussion here and modeled my question after it but I don't understand their solutions and am hoping for something simpler.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions