Is there to make mysql ignore conditions if a variable isn’t set, e.g.
SELECT *
FROM foo
WHERE id = $id
AND bar = $baz
If $baz is set run query as normal, else run the query minus the AND clause?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t know if MySQL ever uses short circuit evaluation in its execution plan, but it may be beneficial to put the cheaper comparison first, like:
You can use this methodology with multiple parameters.