Solved

Correlated subquery in an update statement?

Posted on 1998-11-02
1
1,028 Views
Last Modified: 2008-03-17
I have used correlated sub-queries in select statements, -- and I have used embedded selects in update statements, BUT can you you use correlated sub-queries with update statements?

something like:

UPDATE carts SET carts.format_code = prices.format_code
WHERE cart_item_id IN
      (SELECT cart_item_id from prices, carts
       WHERE  blah blah blah.....)
0
Comment
Question by:edwardk091997
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
avico earned 50 total points
ID: 1082395
the above update is incorrect :

UPDATE carts SET carts.format_code = prices.format_code
WHERE cart_item_id IN
      (SELECT cart_item_id from prices, carts
       WHERE  blah blah blah.....)

the 'prices' table is unknown to the update statement, and only exists in the sub-select.

However, you can issue the following update commnad in order to get the requested affect :
UPDATE carts c, prices p
SET c.format_code = p.format_code
WHERE c.cart_item_id IN
      (SELECT t.cart_item_id from prices r, carts t
       WHERE  r.<price_table_key> = p.<price_table_key>
       AND    blah blah blah.....)

Hope it answered your question.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question