SELECT * FROM table1 join table2 on table2.primarykey= COALESCE( -- If the Foreign Key exists, I want to join on that table1.foreignKey - but if it doesn't, I'll create a join on another field (through an intermediate table) ,(SELECT * FROM intermediateTable where ???=anotherfield) and if there's no corresponding record in the intermediate table, I'll try a join on another field before finally giving up and returning a NULL. ,(try with another table) )