Find the first missing value
I would use the ROW_NUMBER function to assign the "correct" sequence identifier number. Assuming that the sequence identifier is restarted each time the employee identifier changes:
SELECT e.id, e.name, e.employee_number, e.relation, e.familyid, ROW_NUMBER() OVER(PARTITION BY e.employeeid ORDER BY familyid) - 1 AS sequenceid FROM employee_members e
Then, I would like to filter the result set only to include rows with inappropriate sequence identifiers:
SELECT * FROM ( SELECT e.id, e.name, e.employee_number, e.relation, e.familyid, ROW_NUMBER() OVER(PARTITION BY e.employeeid ORDER BY familyid) - 1 AS sequenceid FROM employee_members e ) a WHERE a.familyid <> a.sequenceid
Then again, you need to easily group employee_number and find the first identifier of the missing sequence for each employee:
SELECT a.employee_number, MIN(a.sequence_id) AS first_missing FROM ( SELECT e.id, e.name, e.employee_number, e.relation, e.familyid, ROW_NUMBER() OVER(PARTITION BY e.employeeid ORDER BY familyid) - 1 AS sequenceid FROM employee_members e ) a WHERE a.familyid <> a.sequenceid GROUP BY a.employee_number
Search for all missing values
Extending the previous query, we can find the missing value each time the difference between familyid and sequenceid changes: