Problem statement:
given a range
x -> y
of unsigned integers
wherex
andy
are both in the range
I am a little unclear on what your data really looks like. The problem statement, although well-formulated, seems to have little relationship with the query.
Let me assume that dhcp_range
has the data. The query that you want is:
SELECT COALESCE(MIN(dr.end_address) + 1, 0)
FROM dhcp_range dr
WHERE NOT EXISTS (SELECT 1
FROM dhcp_range dr2
WHERE dr.end_address + 1 BETWEEN dr.start_address AND dr.end_address
);