Tricky SQL - Select non-adjacent numbers

Posted by Daniel on Stack Overflow See other posts from Stack Overflow or by Daniel
Published on 2010-04-19T08:55:43Z Indexed on 2010/04/19 9:13 UTC
Read the original article Hit count: 701

Filed under:
|

Given this data on SQL Server 2005:

SectionID Name  
1         Dan  
2         Dan  
4         Dan  
5         Dan  
2         Tom  
7         Tom  
9         Tom  
10        Tom  

How would I select records where the sectionID must be +-2 or more from another section for the same name.

The result would be:

1 Dan  
4 Dan  
2 Tom  
7 Tom  
9 Tom

Thanks for reading!

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server-2005