Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

sql check for duplicate and re-order

$
0
0

every time someone inserts or updates a value in a column, it needs to be checked for duplicates and if duplicates are found, the new value in col4 should take stay and the old values should be re-ordered

this is what the table will look like

ID,,

1, 123213, 1213322, 1

2, 123213, 2324312. 2

3, 123213, 3324365. 3

4, 123213, 4324376, 4

5, 123243213, 1435, 1

so now if I insert a new value

6, 123213, 2324399. 2

the table should look like this

ID , ,

1, 123213, 1213322, 1

2, 123213, 2324312. 3

3, 123213, 3324365. 4

4, 123213, 4324376, 5

5, 123243213, 1435, 1

6, 123213, 2324399. 2

same thing with updating the columns, if I change the value of

2, 123213, 2324312. 3

to

2, 123213, 2324312. 4

the new table should look like this

ID,

1, 123213, 1213322, 1

2, 123213, 2324312. 4

3, 123213, 3324365. 3

4, 123213, 4324376, 5

5, 123243213, 1435, 1

6, 123213, 2324399. 2

what's...


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>