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.
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.
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.
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]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With