Jump to content

group by without loosing data


renebati

Recommended Posts

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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.