Untested... (But without schema and sample data how could I test it?);with OrderedTeamMatchesas (select c.id_club, c.name, m.dateMatch, row_number() over(partition by c.id_club order by m.dateMatch) orderingfrom @Club cinner join @Match m on c.id_club in (m.id_Club1, m.id_club2))select otm.id_club, otm.namefrom OrderedTeamMatches otminner join OrderedTeamMatches otm2 on otm.id_club = otm2.id_club and otm.ordering = otm2.ordering - 1where datediff(day, otm.dateMatch, otm2.dateMatch) <= 3
No amount of belief makes something a fact. -James Randi