I’m trying to create a query that will only add AND clauses where certain conditions are met.
This is what I’m after:
SELECT DISTINCT
id
name
active
FROM team
WHERE id = 1234
IF team.active = 'y'
AND team.id IN
{
query
}
ELSEIF team.active = 'n'
AND team.id IN
{
query
}
But I’m not sure how to do this in SQL. Any suggestions?
You use the AND and OR connectives to create the logic.