By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,766 Members | 1,295 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,766 IT Pros & Developers. It's quick & easy.

Update / Delete with Joins

P: n/a
Asking for some sample SQL/SP code to perform updates/deletes with joined
tables.

Example 1:
For every record that is matched on both tables A and B, update a field in
table A.

Example 2:
For every record that is matched on both tables A and B, delete record in
table A.

TIA.

~ Duane Phillips.
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Example 1:

UPDATE table_a
SET col = ? /* Unspecified */
WHERE EXISTS
(SELECT *
FROM table_b
WHERE table_b.key_col = table_a.key_col)

Example 2:

DELETE FROM table_a
WHERE EXISTS
(SELECT *
FROM table_b
WHERE table_b.key_col = table_a.key_col)

--
David Portas
SQL Server MVP
--
Jul 23 '05 #2

P: n/a
Many Thanks!

~ Duane Phillips.

"David Portas" <RE****************************@acm.org> wrote in message
news:k9********************@giganews.com...
Example 1:

UPDATE table_a
SET col = ? /* Unspecified */
WHERE EXISTS
(SELECT *
FROM table_b
WHERE table_b.key_col = table_a.key_col)

Example 2:

DELETE FROM table_a
WHERE EXISTS
(SELECT *
FROM table_b
WHERE table_b.key_col = table_a.key_col)

--
David Portas
SQL Server MVP
--

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.