Search This Blog

Saturday, April 17, 2010

SQL Update query statment

SQL Update query statment
With SQL , The UPDATE function allows you to update a single record or multiple records in a table.

update syntax as is :
UPDATE table1
SET field1 = Value
WHERE field2="XXX";
in above condition filed1 row of table1 will be update with value where field2 value is "XXX".
In update function only one table will be use , if you want to update with multiple table condition then use WHERE EXISTS condition.
Example is :

UPDATE Table1
SET Table1.fieldename1 =
( SELECT table2.name
FROM table2
WHERE table2.fieldname2 = table1.fileld2)
WHERE EXISTS
( SELECT table2.field2
FROM table2
WHERE table2.field2 = table1.field2);

No comments:

Post a Comment