Home   Wordpress   Log in

UPDATE where INNER JOIN is needed

December 4th, 2008 by admin | Filed under Database.

How does one UPDATE a field in a table where the key provided is in another table?

It is actually pretty simple:

UPDATE alias1
SET alias1.MyField = 'NEWDATA'
FROM tblTable1 alias1
INNER JOIN tblTable2 alias2
    ON alias1.ProductId = alias2.ProductId
WHERE alias2.PresentationId = '911'

I hope this makes sense. It is easy to test before running the update by simply replacing the UPDATE with a SELECT for testing to make sure the query is returning the correct data.

SELECT *
FROM tblTable1 alias1
INNER JOIN tblTable2 alias2
    ON alias1.ProductId = alias2.ProductId
WHERE alias2.PresentationId = '911'

If you know a better way to accomplish this, please leave me a comment on this post.

Share Your Thoughts

Download Full Movie Online Hytrin Astérix le Gaulois download movie Close Encounters of the Third Kind download movie Ginger Snaps: Unleashed download movie Back to the Future Part II download movie Awakenings download movie Electric Dreams download movie The Crow: Salvation download movie Tarnation download movie Soleil rouge download movie Darkman download movie Whirlwind download movie The hunchback download movie Life stinks download movie Charlie s angels: full throttle download movie Man to man download movie Music and lyrics download movie