Get another table row on the basis of first table
...
IF ( EXISTS ( SELECT * FROM ... WHERE ... ),  -- "If any row found.."
     ( SELECT ... ),   -- "then run .."
     id ),             -- "If no row found, return .."
...