I'm trying to write a SQL query to find the lowest available/unused ID from a column named internal
that exists in two separate tables:
- machines
- machines_ignore
Data is processed from an external source, and we want to fetch data from all machines that are not in the machines_ignore
table. The ignore table is just a manual table set up by us when we identify machines we don't want to analyze.
I've found scripts that work on a single table (like only the machines table), but as soon as I try to get it working when combining two tables.
Example
Table 1 (machines)
id | internal |
---|---|
1 | 1 |
2 | 2 |
3 | 3 |
4 | 5 |
5 | 6 |
Table 2 (machines_ignore)
internal |
---|
4 |
7 |
8 |
9 |
12 |
Expected result
Based on the example above, this query should output 10, 11, 13 etc.
Any ideas?