mysql - join two tables in one with one id and multiple ids in another table -


i have table content joined content_image. there can different images single content_id. want join them case, according image_size.

in other words, have 1 content, 3 different images sizes. these images in table, want show 1 content, 3 different images in 1 output.

anyway hope code more clear in explanation:

    select c.chapter_id,ch.chapter,c.content_id,            c.cont_head name,            small=(case when ci.image_size=0 contimage_small end),            big=(case when ci.image_size=2 contimage_small end),            c.update_date,            c.record_date       content c                left outer join content_chapter ch on c.chapter_id = ch.chapter_id                left outer join content_image ci on ci.content_id=c.content_id      ch.contentcat_id = 14     order c.update_date desc,c.record_date desc 

and output code:

    <cfoutput query="get_images">         <a class="highslide" target="_blank" onclick="return hs.expand(this, { slideshowgroup: 1 } )" href="/documents/content/#big#"><img src="/documents/content/#small#" title="#name#" border="0" /></a>     </cfoutput> 

the problem generates 2 outputs. in first one, big value populated. in second one, small value populated. if group cfoutput content_id, generate single result, again - big value defined :) want single output both big , small values defined.

thank help!

show 1 content 3 different images in 1 output.

if understanding correctly, trying return single record both image size. achieve result must join image table multiple times: once each of image sizes.

again as dan mentioned above, if wish preserve outer join's filtering on tables must done within join's, not where clause, otherwise end doing implicit inner join instead.

 select c.chapter_id        , ch.chapter        , c.content_id        , c.update_date        , c.record_date        , c.cont_head name        , cis.contimage_small smallimage        , cib.contimage_small bigimage  content c          left outer join content_chapter ch               on c.chapter_id = ch.chapter_id , ch.contentcat_id = 14          left outer join content_image cis               on cis.content_id = c.content_id , cis.image_size = 0          left outer join content_image cib               on cib.content_id = c.content_id , cib.image_size = 2 order c.update_date desc,c.record_date desc 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -