Jump to content

turn rows data into columns data


misc00500

Recommended Posts

this is probably a stupid question to ask but, I was wondering if there was a way to turn attach rows of result set from a subselect into column data of the outer select.  IE.

 

turn this:

 

prop_id |      extra_photo      |      caption

-----------------------------------------------

123      |      1.jpg                |  123 spring

123      |      2.jpg                |  123 fairfax

124      |      3.jpg                |  123 freelance

 

 

into this:

 

 

property_id  |  address  |  city |    caption_1    |  caption_2    | caption_3

---------------------------------------------------------------------------

123            |    blah    |  blah  |  123 spring    |    123 fairfax  |  NULL

124            |    blah    | blah  |  123 freelance |    NULL        |    NULL

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/51794-turn-rows-data-into-columns-data/
Share on other sites

Columns can not be created dynamically.  A group_concat can group all the captions into one column and add a seperator as well... have a look at the group_concat information here: http://dev.mysql.com/doc/refman/4.1/en/group-by-functions.html

Yeah, but in this case, you could "JOIN" these two selects based on the ID column.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.