PDA

View Full Version : combining rows


bugsyrocker
02-12-2006, 05:30 AM
Good evening. I'm looking for some SQL help. Perhaps using some sort of combine or concat function

here are a few sample rows from the database...

12 3 2005 blahb lahb
12 3 2005 asdf adf
12 3 2005 wel well well
12 2 2005 yee haw!
12 1 2005 howdy

i want to combine rows together, and include a carriage return, where MONTH, DATE, and YEAR are the same between rows, so afterwards it would return...

12 3 2005 blahb lahb
asdf adf
wel well well
12 2 2005 yee haw!
12 1 2005 howdy


Any suggestions?

Thanks in advance.

hyperbole
02-12-2006, 07:20 PM
I don't think you can do that as a pure SQL command. You need to read the results of the SQL command into a scripting language like Perl, PHP, or C and modify the results there before printing.



.

raf
02-12-2006, 09:20 PM
welcome here!

you can do that by using groupconcat. lik this

SELECT col1, col2, col3, GROUP_CONCAT(col4 SEPARATOR '<br />') FROM yourtable GROUP BY col1, col2, col3

or whatever seperator you want