Reputation: 45
I's posible update table with two where?
UPDATE table_name
SET column_name ='test'
WHERE code='605';
Becouse sql syntax with two WHERE not exist? How to solve?
Upvotes: 0
Views: 78
Reputation: 18747
Use AND
or OR
:
Using AND
:
UPDATE table_name
SET column_name ='test'
WHERE code='605'
AND Col='someval'
When you use AND
, it will update the table only if both conditions are satisfied.
Using OR
:
UPDATE table_name
SET column_name ='test'
WHERE code='605'
OR Col='someval'
When you use OR
, it will update the table if any one of the conditions are satisfied.
EDIT:
For joining another table in UPDATE query:
UPDATE T1
SET column_name='test'
FROM table_name T1 JOIN
another_table T2 on T1.PK=T2.FK
WHERE T1.code='605'
AND T2.Column_from_other_table='someval'
Upvotes: 3
Reputation:
You can add some expressions to your where clause:
UPDATE table_name
SET column_name ='test'
WHERE code='605' or code = '907' or code = '534';
That query will update all rows with that codes.
Upvotes: 2