Home Forums SQL Server 2008 T-SQL (SS2K8) if 2nd year and same Programme for same Student, then return no results RE: if 2nd year and same Programme for same Student, then return no results

  • Isn't it as simple as:

    SELECT

    *

    FROM #Students AS s

    WHERE

    s.[Year] = 2009

    AND NOT EXISTS

    (

    SELECT *

    FROM #Students AS s2

    WHERE

    s2.StudentID = s2.StudentID

    AND s2.Programme = s.Programme

    AND s2.[Year] = s.[Year] - 1

    );