Rohatash Kumar

Rohatash Kumar

  • Tech Writer
  • 23.6k
  • 34.8m

Comparing Data in Two Consecutive Rows in SQL Server

Aug 21 2012 11:42 PM
Suppose my database table is looks like below table,

Id               Name    Status

2012-07-16    A        Login
2012-07-16    A        Logout
2012-07-16    A        Login
2012-07-16    A        Login
2012-07-16    A        Logout

In the above table, Two consecutive rows have the same name login then only last row should be display in the output table. AND I want a output like that:

Date            Name     Status

2012-07-16    A          Login
2012-07-16    A          Logout
2012-07-16    A          Login
2012-07-16    A          Logout

How can I do this?  Please help me.

Answers (5)