I am trying to add a condition(subquery) that basically would filter the output but incase the subquery does not return anything, I want this condition to be ignored somehow.
my main query is very long and complicated so I will try to give a simple example here.
set @userid := 55;
select project, userid
from users_projects
where userid IN
(select userid from activeusers)
AND
project IN (select userid from paidprojects where userid = @userid)
So if select userid from paidprojects where userid = @userid returns an empty output, I want this last condition to be ignored.
I tried this
set @userid := 55;
select project, userid
from users_projects
where userid IN
(select userid from activeusers)
AND
project IN (IF count(select userid from paidprojects where userid = @userid)>0, (select userid from paidprojects where userid = @userid), (select userid from activeusers))
but it's not working and I am getting syntax error:(
usersandprojects. Both of this table can each have an additional column likestatusand you can populate that with values likeactive/inactive(users) andpaid/unpaid(projects).