Jump to content


Photo

group by without loosing data


  • Please log in to reply
1 reply to this topic

#1 renebati

renebati
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 30 March 2006 - 01:08 PM

Hello,

(sorry, but my english is not very well. i'm from holland.)

i have a table 'children' like this :

id | child_id | startdate | enddate
------------------------------------------
1 | 1 | jan | jun
2 | 1 | jul | dec
3 | 2 | jan | mar
4 | 2 | apr | nov

Is it possible to group rows with the same child_id, but without loosing de startdate and enddate from other rows?


I want this as output :

id | child_id | startdate1 | enddate1 | startdate2 | enddate2
-------------------------------------------------------------------
1 | 1 | jan | jun | jul | dec
2 | 2 | jan | mar | apr | nov



Is this possible? Thanx to you all.
Greetz Rene

#2 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 30 March 2006 - 01:27 PM

Best I can come up with is use GROUP_CONCAT to output something like this:

id | child_id | GROUP_CONCAT(startdate SEPARATOR '!') | GROUP_CONCAT(enddate SEPARATOR '!')
-------------------------------------------------------------------
1 | 1 | jan!jul | jun!dec
2 | 2 | jan!apr | mar!nov

See here for more info.. You may need to use an ORDER BY in there too.
[a href=\"http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/gro...-functions.html[/a]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users