Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Select when data changes [closed]

I'd like to retrieve an integer value in a SQL Select but only when the data changes, e.g.:

Table data:

50 50 50 52 50 30 30 35 30 30 60 65 60 60

Now I'd like to get this data:

50 52 50 30 35 30 60 65 60

Executing a distinct query, this would not work for me because it would retrieve:

50 52 30 35 60 65

Any ideas?

I'm working with Entity Framework and C#, so suggestions using them would also be appreciated!

Thanks.

like image 740
Voliverio Avatar asked Dec 16 '13 12:12

Voliverio


People also ask

How do you check if a row has been updated in SQL?

One way is to start a transaction, select the contents of the row and compare it to what you're going to update it to. If they don't match, then do the update and end the transaction. If they match, rollback the transaction.

How do I use update and select together in SQL?

The UPDATE from SELECT query structure is the main technique for performing these updates. An UPDATE query is used to change an existing row or rows in the database. UPDATE queries can change all tables' rows, or we can limit the update statement affects for certain rows with the help of the WHERE clause.


1 Answers

List<int> list=...;
var result=Enumerable.Range(0, list.Count- 1)
                     .Where(x=> x== list.Count-1 || list[x]!=list[x+1])
                     .Select(x=>list[x]);
like image 81
Anirudha Avatar answered Sep 30 '22 13:09

Anirudha