I have modeled jobs and it's dependencies in sql tables:
jobs (id, detail, exit\_code)
dependencies (job\_id, dependenet\_job\_id)

Ex: if job 1 depends on 2 and 3, the tables will have the following:  

jobs  

1 "job1" NULL  

2 "job2" NULL  

3 "job3" NULL  

4 "job4" NULL  

dependencies  

1 2  

1 3  

Now I need to find the jobs which can be run next. In above case 2,3 and 4 can be run as they don't have any dependencies. 1 can run only when 2 and 3 are completed successfully (exit code = 0). 

The tables can have hundreds of jobs and multi level dependencies. I have query to get jobs without dependencies using left outer join. But having trouble with finding jobs whose dependencies have been completed successfully. 

thanks.