Jump to content

Recommended Posts

i've read and seen there are variations of what im trying to achieve but havent seen a exact example...what im trying to do is put a where clause in my query depending on if a set variable has a value

CASE WHEN (@category_id IS NOT NULL)
THEN
LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id
JOIN categories c ON c.category_id = sc.category_id AND c.category_id = :category_id
END

is this possible or have i just got the syntax wrong somewhere...thank you guys

Link to comment
https://forums.phpfreaks.com/topic/292112-case-in-where-statement/
Share on other sites

Can't do a conditional JOIN like that.

 

Join the tables regardless. Keep in mind that making categories an inner join that a matching row will be required, even if you're JOINing it against a table which is an outer join, so it should probably be a LEFT JOIN as well.

 

If that doesn't do it, what problem are you trying to fix or what are you trying to accomplish?

Edited by requinix
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.