Jump to content

MySQL conditional query


select

Recommended Posts

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

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

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.

 

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.