Wednesday, March 17, 2010

Update Tables Using Inner Join

You will come across the problem to update a table with the help of joining two tables.

Below is the steps to update a table using joins

  1. Perform a update say UPDATE
  2. Join the tables with condition say FIRSTTABLE AS A INNER JOIN SECONDTABLE AS B ON A.FIELDNAME = B.FIELDNAME
  3. Write the condition which is going to change or update say SET A.FIELDNAME=2, B.FIELDNAME=5
  4. If you have a where condition then add it say WHERE A.FIELDNAME=10
Combine the above steps and form a query as below
UPDATE
FIRSTTABLE AS A INNER JOIN SECONDTABLE AS B
ON A.FIELDNAME = B.FIELDNAME
SET A.FIELDNAME=2, B.FIELDNAME=5
WHERE A.FIELDNAME=10

Simply cool

Hope this helped you.

Happy Coding,
Kumar

0 Comments:

blogger templates | Make Money Online