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
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

Link to comment
Share on other sites

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
Share on other sites

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.