I have a table Orders(OID, OrderType, ODep, ReqUser)
i want to filter like below logic:
SELECT * FROM Orders if (Ordertype='confidential') filter by ReqUser='$UserID' else filter by ODep
i am not sure if it is possible!
In these situations you can generally replace if a then b else c with (a AND b) OR ((NOT a) AND c), like so:
SELECT *
FROM Orders
WHERE (Ordertype='confidential' AND ReqUser='$UserID')
OR (Ordertype<>'confidential' AND ODep)
;
Alternatively, depending on your data, this may work as well:
SELECT *
FROM Orders
WHERE ReqUser='$UserID'
OR (Ordertype<>'confidential' AND ODep)
;
or this:
SELECT *
FROM Orders
WHERE ODep AND (ReqUser='$UserID' OR Ordertype <> 'confidential')
;
ODep evaluates to.Ordertype<>'confidential' clause in your second OR condition.