select Posted October 23, 2009 Share Posted October 23, 2009 Hi, can anyone tell me if I can use some sort conditional statement in this query. "content.fk_pictures = pictures.pid" That's the part I would like to make Conditional, something like, if false (or null maybe) then ignore, else show result. The problem is that if no pictures are present then there's no result. SELECT content.cheader as ch, content.ctekst as ct, pictures.ppath as pp FROM content, section, pictures WHERE content.fk_section = section.sid AND section.sid = 1 AND content.fk_menu = 1 AND content.fk_pictures = pictures.pid I would really appreciate it, if you need more info just tell me what to post. Link to comment https://forums.phpfreaks.com/topic/178731-mysql-conditional-query/ Share on other sites More sharing options...
kickstart Posted October 23, 2009 Share Posted October 23, 2009 Hi I would use a LEFT JOIN. Not 100% sure on what you want, but something like this:- SELECT content.cheader as ch, content.ctekst as ct, pictures.ppath as pp FROM content INNER JOIN section ON content.fk_section = section.sid LEFT OUTER JOIN pictures ON content.fk_pictures = pictures.pid WHERE section.sid = 1 AND content.fk_menu = 1 All the best Keith Link to comment https://forums.phpfreaks.com/topic/178731-mysql-conditional-query/#findComment-942806 Share on other sites More sharing options...
select Posted October 23, 2009 Author Share Posted October 23, 2009 Thank you so much kickstart! That did it; so far so good it works. I really need to get better with INNER JOIN’s. What I am trying to do is this, in one query. Get one or multiply articles (or content) to each page according to URL id and URL section. One or more pictures can be associated with one article. Link to comment https://forums.phpfreaks.com/topic/178731-mysql-conditional-query/#findComment-942838 Share on other sites More sharing options...
kickstart Posted October 23, 2009 Share Posted October 23, 2009 Hi That will give you one row per picture, and also one row if there are no pictures. Should be OK. All the best Keith Link to comment https://forums.phpfreaks.com/topic/178731-mysql-conditional-query/#findComment-942859 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.