Αποτελέσματα Αναζήτησης
If you want to update specific rows (ie where the IDs match) you probably want to do a coordinated subquery. However, since you are using Oracle, it might be easier to create a materialized view for your query table and let Oracle's transaction mechanism handle the details.
6 Δεκ 2017 · Learn about several methods to update data using subqueries in UPDATE statements to make them more effective and easier to maintain in Oracle SQL.
Subquery Method. The first option is to do an update of the DEST_TAB table using a subquery to pull the correct data from the SOURCE_TAB table. Notice the EXISTS predicate to exclude rows from the DEST_TAB table with no matching row in the SOURCE_TAB table.
2 Ιουν 2023 · 5 – Update with Subquery. Works with: Oracle, SQL Server, MySQL, PostgreSQL. Another way to update a table based on a Select query from another table is to use a subquery. UPDATE person SET account_number = ( SELECT account_number FROM account WHERE account.person_id = person.person_id );
4 Αυγ 2024 · Ever found yourself needing to update a bunch of rows in your database, but the condition for the update depends on data from another table? That’s where UPDATE with a subquery comes in handy. Let’s break it down.
UPDATE table2 t2 JOIN table1 t1 ON t1.id = t2.id SET t2.name = t1.name; RESULTS WITH JOIN. if you are set on doing it with a select you could do it like this. UPDATE table2 t2, ( SELECT Name, id FROM table1 ) t1 SET t2.name = t1.name WHERE t1.id = t2.id RESULTS FROM SELECT
You cannot update a table and select directly from the same table in a subquery. You can work around this by using a multi-table update in which one of the tables is derived from the table that you actually wish to update, and referring to the derived table using an alias.