Jump to content

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.

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.