I want to make where clause conditional based on another column. I tried the below code but it gives syntax error
SELECT *
FROM jobs
WHERE CASE
WHEN "jobs"."tags" IS NOT NULL
AND "jobs"."isprivate" = 1 THEN (
Concat(',', "jobs"."tags", ',') LIKE '%,Test,%'
OR
Concat(',', "jobs"."tags", ',') LIKE '%,natures_touch_fork_lift,%' )
ELSE 1 = 1
END;
In the above code, I want search tags only the job is private and the tag has data
Your help is much appreciated.
ORwhich is after theTHENcaseis an expression not a statement - it returns a value, it doesn't allow you to conditionally run a statement. Just try standard AND/OR logic. I should also mention that this will be very bad for performance because by using theconcatfunction on the column in your where clause you make the query unsargable, i.e. unable to use indexes.