Rohatash Kumar

Rohatash Kumar

  • 9
  • 58.8k
  • 34.4m

Comparing Data in Two Consecutive Rows in SQL

Oct 4 2012 5:26 AM
Hi all,

Suppose my database table is looks like below table,

  Id  Date1                          Name  Type
  1  2012-07-16 00:00:00.000  Rohit  A
  1  2012-07-16 00:00:00.000  Rohit  A
  1  2012-07-16 06:00:00.000  Rohit  B
  2  2012-07-16 08:00:00.000  Rahul  A
  2  2012-07-16 20:00:00.000  Rahul  B
  2  2012-07-16 21:00:00.000  Rahul  B 



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

  Id  Date1                          Name  Type
  1  2012-07-16 00:00:00.000  Rohit  A
  1  2012-07-16 06:00:00.000  Rohit  B
  2  2012-07-16 08:00:00.000  Rahul  A
  2  2012-07-16 21:00:00.000  Rahul  B 

How can I do this?  Please help me.

Rohatash

Answers (4)