Update with select table from another table
Hallo,I'd like to update table b with a mapping a table codes.
one has:
town_id, town_code, town_name
b town_code, town_id, town_population, town_zip_code...
Table a has all the details - town_id, town_code and town_name and acts as the mapping between town_id and town_code
In table b, town_code is null. I want to update the column b.town_code with town_code table where a.town_id = b.town_id.
How the update query will look like?
I tried
UPDATE B SET town_code = (SELECT A.town_code FROM A, B WHERE A.town_id = B.town_id)
and I get the error "einreihig subquery returns several lines.
You will appreciate your assistance
OK, now I see where you went wrong.
It's your query:
UPDATE TOWN_INFO
SET TOWN_CODE=(SELECT B.TOWN_CODE FROM TOWN_MAPP B, TOWN_INFO C
WHERE B.TOWN_ID=B.TOWN_ID)
/
You have added an additional TOWN_INFO table reference in your subquery. You really wanted to refer to the TOWN_INFO in your UPDATE statement for that to be a CORRELATED subquery. Delete this reference as I did below.
Here's the correct query:
UPDATE TOWN_INFO TI
SET TOWN_CODE = (
SELECT TOWN_CODE
FROM TOWN_MAPP TM
WHERE TI.TOWN_ID = TM.TOWN_ID
)
;
Tags: Database
Similar Questions
-
Hello
I started with Oracle Database 11g, with apex XE, fact the upgrade of the Apex 4.2.6 and to develop a small Application.
I wanted to connect to my computer (with step of database on this subject) from another computer Windows 7 B.
So I put Firefox: //A:8080/apex but I have only received a timeout.
Of course, on both computers there is a firewall of windows running, so I stopped on both systems, the firewall, but it is always the same.
In Explorer windows running on computer B, I can see data from computer A and both computers are in the same home-net group. (Sorry for my bad English).
Is there anyone who cann tell me how to get the connection running?
Maybe I saw the info on this in the textbooks, if it is there, please give me a hint.
Thank you very much
William Kastner Salzburg
Hello
Check to see if that helps
https://docs.Oracle.com/CD/E17781_01/install.112/e18803/TOC.htm#XEINW127
Kind regards
Jari
-
read in select data from another table
Hello world.
IM Oracle11GR2 database.
I m facing the following problem:
I have 2 tables.
In the first picture, I have a few articles and 3 of these items then come.
(A) point Varchar2
(B) Item Varchar2.
(C) point digital and this point is the id of a record in the other table.
If the digital point > 0 then points A and B must be read in the second table
In the second table, I have 3 Articles.
(A) the id of the record.
B & C point are also point varchar2 and must be read in the first table, point C is > 0.
I'm looking for the way that when I write a normal selection in the first picture he gives me the point B & C of the second table if C point in the first table is > 0.
I thought to solve this problem with a trigger or something similar.
Any idea is welcome.
Regards to everyone.
You don't need a trigger for this. A simple select statement should do. Something like that? I got your if condition perfectly.
SELECT CASE WHEN (T1. C > 0) THEN (SELECT T2. B OF THE T2 WHERE T1. C = T2. (A) T1 OTHERWISE. END A,
BOX WHEN (T1. C > 0) THEN (SELECT T2. C FROM T2 WHERE T1. C = T2. (A) T1 OTHERWISE. B END HAVE B,
T1. C
FROM T1;
Look at the following example. Check if it fills your scenario.
-BEGINNING OF THE SAMPLE DATA
WITH T1 AS)
SELECT 'A' A, 'B' B, 1 C OF DOUBLE UNION ALL
SELECT 'C', ', 2 DOUBLE UNION ALL
SELECT 'DF', 'G', THE DOUBLE 0),
() AS T2
SELECT 1, 'X' B 'Y' C DOUBLE UNION ALL
SELECT 2, 'Z', 'BB' OF THE DOUBLE)
-END OF THE SAMPLE DATA
SELECT CASE WHEN (T1. C > 0) THEN (SELECT T2. B OF THE T2 WHERE T1. C = T2. (A) T1 OTHERWISE. END A,
BOX WHEN (T1. C > 0) THEN (SELECT T2. C FROM T2 WHERE T1. C = T2. (A) T1 OTHERWISE. B END HAVE B,
T1. C
FROM T1;
OUTPUT:
A B C
-- -- ----------
X Y 1 - since c > 0 A and B values in table 2 are replaced
Z BB 2 - since c > 0 A and B values in table 2 are replaced
DF G 0 - since c = 0, there is even value in table 1
Post edited by: Parth272025
-
Can I synchronize my phone with my library from another computer?
My laptop can not be updated beyond iTunes 11.4 because I'm on OSX 10.6. I have access to a desktop Mac with a newer version of iTunes. I turned on home sharing, so the music library on my laptop appears in itunes for the Mac desktop. If I sync my phone on the desk, I'll be able to sync it with the music library on my laptop?
Yes, but a phone can only be synchronized a library at a time. Except if you transfer all of the library to the new computer (which may have several libraries) iTunes will want to erase your phone before it sync to the other library, which is the same as the old media. In the concept that shouldn't matter since both libraries should have the same content of media.
-
Why my product key not valid with an installation from another CD as the original?
I had to reload a fresh install of Win XP on a Toshiba laptop. Given that the previous owner had lost the CD; I took one I had at home a try to install it on my laptop with laptop computer product key stuck under the laptop. but when I try to install said that it is a key of product not valid. This is false because before to format the laptop, it had windows XP installed with this product key and it worked fine. I sort of... ending up with the fact that the installation needs a corresponding product key... Am I wrong? If Yes, what can I do if I want to use my laptop product key and I don't have the Original CD of Installation?
Thank you!
You have installed using the installation XP bad disc. XP installation disks are related to the version of the operating system and the type of installation for each particular product key. You need to install either with the recovery media OEM Toshiba (best solution, solved by ordering the recovery disc from Toshiba for a little money - usually less than $30) OR a generic OEM installation disk for the version for installed XP (Home/Pro/Media Center). If you use a generic OEM installation disc, then you will enter the product key for the thumbnail of the laptop. If you use a generic OEM install disc, then you should go to the Web from Toshiba site and download/install all the drivers and utilities for this laptop model. There is always a ton of them.
To contact Toshiba support, buy recovery disks, do an install clean/restore factory with these discs. You won't need to enter a product key if you use the restore disks.
MS - MVP - Elephant Boy computers - don't panic!
-
I tried to replace the current hard drive with the disc provided with windows 10 from another PC.
I have is after having swapped the hard drive. The system cannot load Windows 10 and displays this message "ERROR CODE 1962 - No. OPERATING SYSTEM".
The main reason I like to swap the drive is because it is a larger and faster disk and it come with Windows 10 Enterprise license. Instead of my current hard drive of Levono who only 8.1 Windows
I understand that the pilot is maybe a problem. But, I should at least be able to see the Windows screen and I can fix it the driver, instead of the message "ERROR CODE 1962 - No. OPERATING SYSTEM"
Note: I did I tried to put this disc in the CD player, I've found, it can read the disc. Therefore, should not be SATA non-compliance issue.
Any suggestion?
Hope to hear the suggestion
Dear all
I managed to fix in Boot "Disable UEFI and activate the legacy", my system is running. I just need to install the audio driver after the system is running
Usefully it doesn't matter who will help to have the same problem
-
How can I update this table with values from another table?
Hello
I have a table 'governed '. I want to replace the values in the column "regies.agent" by the value of the column "regies_personnes.id."
As you can see the tables have a column of common values. IE regies.agent = regies_personnes.nom
Table 'governed ':
Insert into 'authorities' (AGENT) values ('Humberdot Alain");
Insert into 'authorities' (AGENT) values ("Danard Patrick");
Table 'regies_personnes ':
Insert into REGIES_PERSONNES (NAME, ID) values ("Humberdot Alain", 1);
Insert into REGIES_PERSONNES (NAME, ID) values ("Danard Patrick", 2);
Before having it
SQL > select agent of authorities;
Humberdot Alain
Patrick Danard
After the update, the result should be
SQL > select agent of authorities;
1
2
Thank you for your kind reply.You can
update regies r set agent = (select id from regies_persones p where r.agent = p.nom) where exists (select id from regies_persones p where r.agent = p.nom)
-
Update the values in the Table from another Table containing historical data
So, I have two tables, a table and a master table. The current table is updated each week and at the end of the week, is copied to the main table to keep historical data. I have update the table in progress early in the week and want to take the latest data from the master table and update the current table with the data. The current table could have additional IDs or some of the IDS could have deposited (these lines would receive data in the main table). I want to only update the rows in the current table that have existing data to the attr1, attr2, attr3 columns. A particular ID may have more than one record in the primary table, I want only the last disk to use for updating the current table. The data from a different database where no direct connection is possible then I have to import data every week. Here are some statements of create/insert:
create table current_T (ID1 varchar(100),adate date,attr1 varchar(100),attr2 varchar(100),attr3 varchar(100))
create table Master_T (ID1 varchar(100),adate date,attr1 varchar(100),attr2 varchar(100),attr3 varchar(100))
begin insert into current_T (ID1,adate) values ('IE111','08/02/13'); insert into current_T (ID1,adate) values ('IE112','08/02/13'); insert into current_T (ID1,adate) values ('IE113','08/02/13'); insert into master_T (ID1,adate,attr1,attr2,attr3) values ('IE111','08/01/13','yes','abc','123'); insert into master_T (ID1,adate,attr1,attr2,attr3) values ('IE112','08/01/13','no','dgf','951'); insert into master_T (ID1,adate,attr1,attr2,attr3) values ('IE113','08/01/13','no','dgf','951'); insert into master_T (ID1,adate,attr1,attr2,attr3) values ('IE113','07/01/13','no','dgf','951'); end;
This has been a scratcher for me head and any help would be greatly appreciated. I'm coding in Apex 4.1
Thank you
-Steve
Not tested
merge into current_t c
using (select *)
Of
(select m.*
row_number() over (partition by m.id1 m.adate DESC order) rn
of master_t m
)
where rn = 1
) u
on (c.id1 = u.id1)
When matched then update
Set c.adate = u.adate
c.attr1 = u.attr1,
c.attr2 = u.attr2,
c.attr3 = u.attr3,
When not matched then insert
(c.id1, c.adate, c.attr1, c.attr2, c.attr3)
values
(u.id1, u.adate, u.attr1, u.attr2, u.attr3)
;
-
Hello world
IM pretty new to audit the database. Auditing is enabled in the database. I would like to retrieve the news all of the objects belonged to a certain pattern when it was last accessed (select, insert, update) with time stamp. Is there any script for this? Your time and your reply is greatly appreciated. Thank you.
Database version: 11.2.0.4
Enable audit is not quite enough to get the details when the table is updated/inserted/selected.
You must activate audting on the object level, then you may only be able to see your report of your choice.
SELECT OBJ_NAME, ACTION_NAME, to_char (timestamp, ' dd/mm/yyyy, hh') of sys.dba_audit_object.
-
How to update one table from another table
Hello
I have two tables, t1 or t2, I wrote the below query, but got an error as ORA-00904 ' identifier Inavlid b.purchase_capturedate. The query is:
Update t1 a
Set a.docdate = b.purchase_capturedate
where (a.docid))
Select docid_request from t2 b where a.docid = b.docid_request and b.itemcategoryid = 6)
Help, please.
Kind regardsHello
describe your tables t1 and t2
Concerning
Sankar MN -
ODI 12 c: IKM for differential insert and update with a sequence in the target table
Hello
I have a map where I fill in a column of my target table using a database sequence. Now my mapping is supposed to load the target gradually table. So I need a revenge for update and incremental insert. Now with this differential IKM it compares all the columns to match all colmuns line to understand, it should be an insert or update. Now, the following code shows that when the ROW_WID is loaded with a sequence of database.
If NOT EXISTS
(select 1 from W_LOV_D T
where T.ROW_WID = S.ROW_WID
and ((T.CREATED_BY = S.CREATED_BY) or (T.CREATED_BY IS NULL and S.CREATED_BY IS NULL)) and
....
....
< the rest of the comparison of columns >
)
So when running ODI returns following error
Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "S". "" ROW_WID ": invalid identifier
Please suggest if there is no other IKM I should use or if there is another way around it without changing the code IKM...
Hi Marc,
Thanks for your reply.
I had solved it. The incremental update process inserts all rows from the source table to I$ table that exists in the target table. It does so by the where sql such as mentioned in my questions as
WHERE THERE is NOT (
. COLUMNS = -
Script table with Clob and record another database
Hello
How can I read the Clob column data and insert into another table in the database.
The first Table is quality Test and second Production
Is there a way without using Export / Import?
What can I use the charger?
With the help of 9imuttleychess wrote:
mschnatt wrote:
You can only try the db-linkCREATE LINK
of the DATABASE to CONNECT to IDENTIFIED BY with the HELP of " "; and make the table
create table...
in select...Thank you, but too no work :-(:-(
SQL> select id,clob_data from myclob@teste; select id,clob_data from myclob@teste * ERRO na linha 1: ORA-22992: cannot use LOB locators selected from remote tables
Well you don't have the answer said to
and make the table
create table...
in select...Also in the manual, you could save a lot of time if you open.
http://docs.Oracle.com/CD/B14117_01/AppDev.101/b10796/adlob_wo.htm#1006314
>
The following syntax is supported on the remote LOB columns:CREATE TABLE t AS SELECT * FROM table1@remote_site; INSERT INTO t SELECT * FROM table1@remote_site; UPDATE t SET lobcol = (SELECT lobcol FROM table1@remote_site); INSERT INTO table1@remote_site select * from local_table; UPDATE table1@remote_siteset lobcol = (SELECT lobcol FROM local_table); DELETE FROM table1@remote_site
It is the only syntax support involving some LOBs in remote tables. No other use is supported.
-
Update using several terms from multiple tables
Hello
I'm quite new to PL/SQL.
I need to update a record in a table with several conditions in which the clause of several tables.
On the internet I found something like
Update < table >
Set < column > = < value >
< Table >
Join them < table >
on < condition >
Where < condition >
And < another condition >
Now, I have:
Update outbound_order
Set outbound_order_sorting_code = "A".
to orderref o, oo outbound_order
where oo.ordernumber = o.ordernumber
and o.delivery_status = 'c ';
It gives ORA00933 of Pl/SQL to->
I can't use more than one table in update?
Kind regards
Chi Waiupdate outbound_order o set outbound_order_sorting_code = 'A' where exists(select 1 from orderref oo where oo.ordernumber = o.ordernumber) and delivery_status = 'c';
-
Hallo,
I have an af:table that displays the result of a custom search form.
I need to update the properties of some of the buttons every time that a row in the table is selected.
I would like to handle this in a SelectionListener I associated with the table.
public void myTableSelectionListener(SelectionEvent selectionEvent) { ELUtils.invokeEL("#{bindings.SearchEmployee1.collectionModel.makeCurrent}", new Class[] { SelectionEvent.class }, new Object[] { selectionEvent }); Row selectedRow = (Row) ELUtils.evaluateEL("#{bindings.SearchEmployees1Iterator.currentRow}"); System.out.println(selectedRow.getAttribute("Name") + " - " + selectedRow.getAttribute("Surname")); }
I noticed the System.out.println prints the values of the selected line only when the user clicks on a line while that no value does print when the grid is recharged after clicking the search button.
To resolve this problem, I guess I need to select by program level 1 in the table whenever the grid is charged, but I have not found a working method to do this.
You kindly explain how to select by program level 1 of an af:table?
Thank you
Federico
Hi Federico
only for research you can handle this in your action of the search button (because your selection listener code works for another action), after research get the current row of your table (it would be the first rows) and run your codeIf you are using af:query, then override default query listener to run custom code
Thank you
-
How update the relational table with XML data?
I get XML messages that include a bunch of data items to be updated in a table. An arbitrary subset of rows is updated for each message received.
The output of the following example is correct, but the use of the intermediate table that bothers me. The temporary table can be eliminated somehow? Or is the most reasonable way to loop just explicitly and parse the XML message and then update each row separately?
I'm under 11.2.0.1.0.
create table otn9test ( id number not null primary key, data xmltype ); insert into otn9test values (1, xmltype('<data>default for 1</data>')); insert into otn9test values (2, xmltype('<data>default for 2</data>')); insert into otn9test values (3, xmltype('<data>default for 3</data>')); create table otn9input ( id number, data xmltype ); column data format a30 declare updata constant xmltype := xmltype('<root> <item> <id>1</id> <data>Id 1 updated.</data> </item> <item> <id>3</id> <data>Id 3 updated.</data> </item> <item> <id>4</id> <data>Id 4 updated.</data> </item> </root>'); begin insert into otn9input select * from xmltable('/root/item' passing updata columns id number path 'id', data xmltype path 'data'); update otn9test t set data = ( select data from otn9input i where t.id = i.id ) where t.id in (select id from otn9input); commit; end; / select * from otn9input; /* ID DATA ---------- ------------------------------ 1 <data>Id 1 updated.</data> 3 <data>Id 3 updated.</data> 4 <data>Id 4 updated.</data> */ select * from otn9test; /* ID DATA ---------- ------------------------------ 1 <data>Id 1 updated.</data> 2 <data>default for 2</data> 3 <data>Id 3 updated.</data> */ drop table otn9input; drop table otn9test;
The temporary table can be eliminated somehow?
You can do it with the MERGER:
merge into otn9test t using ( select id, data from xmltable('/root/item' passing updata columns id number path 'id', data xmltype path 'data' ) ) x on ( t.id = x.id ) when matched then update set t.data = x.data ;
However, if you are looking for performance on large data sets, I think that the best is to use an intermediate table of XMLType (binary storage) to maintain the XML instance.
create table otn9input of xmltype xmltype store as securefile binary xml; insert into otn9input values( xmltype('
1 Id 1 updated.3 Id 3 updated.4 Id 4 updated.A structured XMLIndex could also help.
Maybe you are looking for
-
Mail displays false name when viewing emails
When I open a new email I received in the mail application, there is a name in my contacts that the message always says this is to and from, no matter what the message is actually to or from. The same thing happens when I'm composing a response. For
-
S good for Satellite 1400-253 DVD burner need
Could someone give me the part number for the Toshiba dvd writer/burneror offer any compatible dvd burner to fit one Computer portable satellite 1400-253 s (ide connection) Thank you
-
On the Satellite L650-19W keyboard problems
Hello A very strange and annoying problem developed on my laptop about four days ago. First of all, here's my laptop specs: Satellite L650 - 19W8 GB RAM (DDR3)Windows 7 64 bitIntel Core i5 CPU The problem is that some of the keys also trigger others.
-
For some reason my save attachments is grayed out and it allows me to save an attachment in My Documents (default setting). Currently, he is ordered to save attachments to a disk. How can I reset the default setting to My Documents?
-
Windows cannot start the windows Vista Firewall service
My system is windows vista. When I tried to 'turn on the windows firewall' the message I got was ' Windows Firewall settings cannot be displayed because the associated service is not running. You want to start the windows firewall service? "I clicked