Tuesday, 10 September 2013

Deleting database existing record while asigning values from one row to other with unique values

Deleting database existing record while asigning values from one row to
other with unique values

I'm fairly new to sql and cant find a solution to make an update query. I
have the following table
Table: order
id | cid | pid
1 | 1 | 1
2 | 1 | 2
3 | 2 | 2
4 | 2 | 3
I want the cid of 2 to become 1, BUT not updating rows which have same
pid. The result i want is:
id | cid | pid
1 | 1 | 1
2 | 1 | 2
3 | 2 | 2
4 | '1' | 3
UPDATE order SET cid=1 WHERE cid=2 AND 1.product_id <> 2.product_id;

No comments:

Post a Comment