• You'll probably need a query that GROUP BY the name column. Combine this with a HAVING search condition that checks for MIN(), MAX() and COUNT(DISTINCT ) should get you what you want.

    GROUP BY

    HAVING

    Alternatively, you can solve this problem by having two joins to the same table, but joining to the previous and next ID values, respectively.

    Looking forward to see what query you come up with 🙂