Hi,
I need to Copy all values of a column from one table to another. Below are the details:
Source: STL_GRP table, VEND column
Destination PARTNER table, VEND column.
I am using the below query which is incorrect: -
-
UPDATE PARTNER
-
SET VEND=
-
(
-
SELECT DISTINCT STL.VEND
-
FROM STL_GRP STL, PARTNER PRT
-
WHERE PRT.PARTNER_CD = STL.PARTNER_CD
-
)
-
This query is returning error: "ORA-01427: single-row subquery returns more than one row", which is true.
Can someone suggest an alternative to do this? Any help will be appreciated. Thanks.
7 3900
What do you expect the database to return if it found two rows in the second table that matches the current row? And also these values are different??? (so they are not filtered out by DISTINCT?
Take the first one or the second one? Concatenate data of first and second one and then store?
I mean you must make your "where" clause in a way that exactly one record of source table matches exactly one record (or none) in destination table.
You can do that by making sure the matching keys PRT.PARTNER_CD = STL.PARTNER_CD are unique in both tables. Or filter out more inside your where clause, by matching with a second column.
Or matching with min(rownum) to get the first record.
Hi,
I need to Copy all values of a column from one table to another. Below are the details:
Source: STL_GRP table, VEND column
Destination PARTNER table, VEND column.
I am using the below query which is incorrect:
UPDATE PARTNER
SET VEND=
(
SELECT DISTINCT STL.VEND
FROM STL_GRP STL, PARTNER PRT
WHERE PRT.PARTNER_CD = STL.PARTNER_CD
)
This query is returning error: "ORA-01427: single-row subquery returns more than one row", which is true.
Can someone suggest an alternative to do this? Any help will be appreciated. Thanks.
Try using EXISTS and check if it works. -
-
UPDATE PARTNER
-
SET VEND=
-
(
-
SELECT DISTINCT STL.VEND
-
FROM STL_GRP STL, PARTNER PRT
-
WHERE PRT.PARTNER_CD = STL.PARTNER_CD
-
)
-
WHERE EXISTS (SELECT DISTINCT STL.VEND
-
FROM STL_GRP STL, PARTNER PRT
-
WHERE PRT.PARTNER_CD = STL.PARTNER_CD)
-
-
So what is the difference of the original and the solution below?
The SQL below does not solve the issue with 2 matching records.
The only difference I can see is that if a record does not exist in second table, no copy into first table is done instead of assigning null value there.
Try using EXISTS and check if it works. -
-
UPDATE PARTNER
-
SET VEND=
-
(
-
SELECT DISTINCT STL.VEND
-
FROM STL_GRP STL, PARTNER PRT
-
WHERE PRT.PARTNER_CD = STL.PARTNER_CD
-
)
-
WHERE EXISTS (SELECT DISTINCT STL.VEND
-
FROM STL_GRP STL, PARTNER PRT
-
WHERE PRT.PARTNER_CD = STL.PARTNER_CD)
-
-
So what is the difference of the original and the solution below?
The SQL below does not solve the issue with 2 matching records.
The only difference I can see is that if a record does not exist in second table, no copy into first table is done instead of assigning null value there.
Mistake!! I meant with few more conditions or with Aggregate function to select single value from more than one records returned by the query!!
I will re-phrase the problem. If there are multiple entries of VEND in STL_GRP, then first entry should be picked up.
Now, certainly below query will not help me, as internal query returns all the VEND values not just first one. Can you suggest something? -
-
UPDATE PARTNER
-
SET VEND=
-
(
-
SELECT DISTINCT STL.VEND
-
FROM STL_GRP STL, PARTNER PRT
-
WHERE PRT.PARTNER_CD = STL.PARTNER_CD
-
)
-
-
Try This: -
-
UPDATE PARTNER PRT
-
SET PRT.VEND=
-
(
-
SELECT DISTINCT STL.VEND
-
FROM STL_GRP STL
-
WHERE PRT.PARTNER_CD = STL.PARTNER_CD
-
AND STL.ROWID = (SELECT MAX(ROWID) FROM STL_GRP ST WHERE PRT.PARTNER_CD = ST.PARTNER_CD))
-
-
try limit 1 if you only want the first returned.... -
UPDATE PARTNER
-
SET VEND=
-
(
-
SELECT DISTINCT STL.VEND
-
FROM STL_GRP STL, PARTNER PRT
-
WHERE PRT.PARTNER_CD = STL.PARTNER_CD limit 1
-
)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Agoston Bejo |
last post by:
I want to enforce such a constraint on a column that would ensure that the
values be all unique, but this wouldn't apply to NULL values. (I.e. there
may be more than one NULL value in the column.)
How can I achieve this?
I suppose I would get the most-hated "table/view is changing,
trigger/function may not see it" error if I tried to write a trigger that
checks the uniqueness of non-null values upon insert/update.
|
by: C G |
last post by:
Dear All,
I'm trying to insert an xml file into my database. I have a table with a
single text column. My intention is just to have the xml file take up one
row in the table.
I've tried the command
COPY t1 FROM '/tmp/file.xml';
|
by: Robert Fitzpatrick |
last post by:
Does COPY require values for each column even though the database field
is not set to NOT NULL? I did a COPY TO first to line up the data and
then COPY FROM a tab delimited file. Here are the first 5 fields in the
first line of the incoming file (omit the quotes, I put them there to
see where the start and end of the line is), you should find 3 tabs
after the second '1':
'1 1 '
I have a table with this structure below and when...
|
by: Blazej |
last post by:
First of all I want to say Hi to every one. So.. Hi :)
I'm new in Access, so please be patient. I've got this problem:
I have a subform, where user can see results from one table called A. There is a checkbox in one of the columns in this table.
What I want to do is to copy the specific row, after user will check the checkbox, as a new row to another table called B. But I don't want to make exact copy, but only values from three columns...
|
by: GTi |
last post by:
I have two identical tables with one IDENTITY column and several other
columns.
I have tested the COPY * INTO table2 FROM table1 WHERE xx
but it requers that table2 does not exist.
TABLE2 is a history database of TABLE1
How can I copy row(s) from table1 to table2 without conflict with
IDENTITY columns using SQL query.
Or must I do this from a program (C# .NET)
| |
by: pbd22 |
last post by:
Hi.
Like the title says - how do i do this?
I was given the following example:
INSERT INTO TABLE2 SELECT * FROM TABLE1 WHERE COL1 = 'A'
The above statement threw the following error:
|
by: NamelessNumberheadMan |
last post by:
I have a table I need to make changes to. Dropping columns isn't my problem, but before I drop one of the columns I need to copy the values that aren't null to another existing column in the same table. So for psuedo-code it would be something like:
update Mapping Set SID = (select SMappingID from Mapping where SMappingID is not null)
I don't know if I should be doing this in a loop (which I'm not totally familiar with using) or if there...
|
by: NamelessNumberheadMan |
last post by:
I have a table I need to make changes to. Dropping columns isn't my problem, but before I drop one of the columns I need to copy the values that aren't null to another existing column in the same table. So for psuedo-code it would be something like:
update Mapping Set SID = (select SMappingID from Mapping where SMappingID is not null)
I don't know if I should be doing this in a loop (which I'm not totally familiar with using) or if there...
|
by: Manuel |
last post by:
Hi to all,
I'm trying to copy a Datacolumn from a table to another, but with this code:
destTable.Columns.Add(srcTable.Column);
I got this error:
Column 'colname' already belongs to another DataTable.
Anyone can help me?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |