SELECT * FROM instances LEFT JOIN quotes ON quotes."instanceId" = instances.id WHERE "instances"."stageId" IN (3,4,5) AND NOT EXISTS ( SELECT quotes.id FROM quotes WHERE quotes."instanceId" = instances.id ) ORDER BY instances.id DESC;