I need to run a query dependent on the value of a field read by that specific query. This is my query :
SELECT * FROM foo JOIN bar ON bar.ID = foo.field1
if foo.field1 is 0, the JOIN is to be made on foo.field2
I've tried something like
SELECT * FRMO foo JOIN bar ON bar.ID = (SELECT field1 FROM bar WHERE field1 != 0)
but I'm not sure how how to write the next part, for when field1 is actually 0.
Please advise. Thanks!