Reputation: 687
I want to update values in tables that for any set of data in two columns, the third column is same. For example
Column1| Column2| Column3|
| | |
1| 2| 3|
2| 1| 4|
5| 6| 7|
After the query the result output should be
Column1| Column2| Column3|
| | |
1| 2| 3|
2| 1| 3|
5| 6| 7|
as in values (1, 2) and (2, 1) in column1 and column2 should have same values for column3
Upvotes: 0
Views: 122
Reputation: 2097
Use a self-join:
UPDATE your_table t1 -- Your table goes here
SET [Column3] = rand()
FROM your_table t2 -- and here
WHERE (t1.[Column1] = t2.[Column1] AND t1.[Column2] = t2.[Column2]) OR
(t1.[Column1] = t2.[Column2] AND t1.[Column2] = t2.[Column1])
Upvotes: 1