Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6793153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:04:00+00:00 2026-05-26T18:04:00+00:00

I am not able to understand the issue with the following SQL query. I

  • 0

I am not able to understand the issue with the following SQL query. I am trying to copy column ABC from table TABLE3 to TABLE1 with TABLE2 having the common column between the two.

UPDATE TABLE1 CS  
  SET CS.ABC = TC.ABC  
WHERE CS.COMMON_COLUMN = (  
    SELECT CGL.COMMON_COLUMN 
    FROM TABLE2 CGL, 
         TABLE3 TC  
    WHERE   CGL.PRD_ID = TC.PRD_ID  
    AND  CGL.PRD_VER = TC.PRD_VER  
    AND  CGL.PY_ID = TC.PY_ID  
    AND  CGL.TPY_ID = TC.TPY_ID  
)

I am running into the error:

SQL Error: ORA-00904: “TC”.”ABC”: invalid identifier
00904. 00000 – “%s: invalid identifier”
*Cause:
*Action:

[edit; Please read the explanation below]
So I have updated the query to make more sense w.r.t my explanation. Table1 and Table2 are connected by 4 columns PRD_ID, PRD_VER, PY_ID and TPY_ID. This combination finds multiple rows in Table2 since it is not unique/primary key combination. For each row retrieved from Table2, the column common_column is what is needed to update Table3 since common_column only associates with one row.

Example.

Table1

 PRD_ID, PRD_VER, PY_ID, TPY_ID, COLUMN_USED_FOR_UPDATE
 ------------------------------------------------------  
      1     , 1      , 1    ,1  ,     VALUE1
      2     , 3      , 4    , 5 ,     VALUE2

Table2

 PRD_ID,  PRD_VER,  PY_ID,  TPY_ID, COMMON_COLUMN
  ------------------------------------------------
    1  ,     1     , 1,         1,         A
    1  ,     1     , 1,         1,         B
    2,       3     , 4,         5,         C

Table 3

        COMMON_COLUMN, .... , COLUMN_TO_UPDATE
-------------------------------------------------------
           A,         .....  , null
           B,       ....     , null
           C,          .... ,   null

So after I execute the query, Table3 should look like this:

        COMMON_COLUMN, .... , COLUMN_TO_UPDATE
-------------------------------------------------------
           A,         .....  , VALUE1
           B,       ....     , VALUE1
           C,          .... ,   VALUE2
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:04:00+00:00Added an answer on May 26, 2026 at 6:04 pm

    I’m guessing that you want

    UPDATE table1 cs
       SET cs.abc = (SELECT tc.abc
                       FROM table2 cgl,
                            table3 tc
                      WHERE cgl.prd_id       = tc.prd_id
                        AND cgl.prd_ver      = tc.prd_ver
                        AND cgl.py_id        = tc.py_id
                        AND cgl.typ_id       = tc.tpy_id
                        AND cd.common_column = cgl.common_column)
     WHERE EXISTS (SELECT 1
                     FROM table2 cgl,
                          table3 tc
                    WHERE cgl.prd_id       = tc.prd_id
                      AND cgl.prd_ver      = tc.prd_ver
                      AND cgl.py_id        = tc.py_id
                      AND cgl.typ_id       = tc.tpy_id
                      AND cd.common_column = cgl.common_column)
    

    Update: Other than the changes to the column and table names, my initial answer appears to work with the sample data you posted. Note that it’s always easier to post DDL and DML so that we can reproduce your tables and data rather than having us convert your data to DDL and DML.

    If I create your tables and data

    SQL> create table table1 (
      2    prd_id number,
      3    prd_ver number,
      4    py_id number,
      5    typ_id number,
      6    column_used_for_update varchar2(10)
      7  );
    
    Table created.
    
    SQL> begin
      2    insert into table1 values( 1, 1, 1, 1, 'VALUE1' );
      3    insert into table1 values( 2, 3, 4, 5, 'VALUE2' );
      4  end;
      5  /
    
    PL/SQL procedure successfully completed.
    
    SQL> create table table2 (
      2    prd_id number,
      3    prd_ver number,
      4    py_id number,
      5    typ_id number,
      6    common_column varchar2(10)
      7  );
    
    Table created.
    
    SQL> begin
      2    insert into table2 values( 1, 1, 1, 1, 'A' );
      3    insert into table2 values( 1, 1, 1, 1, 'B' );
      4    insert into table2 values( 2, 3, 4, 5, 'C' );
      5  end;
      6  /
    
    PL/SQL procedure successfully completed.
    
    SQL> create table table3 (
      2    common_column varchar2(10),
      3    column_to_update varchar2(10)
      4  );
    
    Table created.
    
    SQL> begin
      2    insert into table3 values( 'A', null );
      3    insert into table3 values( 'B', null );
      4    insert into table3 values( 'C', null );
      5  end;
      6  /
    
    PL/SQL procedure successfully completed.
    
    SQL> commit;
    
    Commit complete.
    

    Then adjust the table and column names from my initial answer, it appears that the update works correctly

    SQL> ed
    Wrote file afiedt.buf
    
      1  UPDATE table3 t3
      2     SET t3.column_to_update = (
      3                   SELECT t1.column_used_for_update
      4                     FROM table2 t2,
      5                          table1 t1
      6                    WHERE t1.prd_id        = t2.prd_id
      7                      AND t1.prd_ver       = t2.prd_ver
      8                      AND t1.py_id         = t2.py_id
      9                      AND t1.typ_id        = t2.typ_id
     10                      AND t3.common_column = t2.common_column)
     11   WHERE EXISTS (  SELECT 1
     12                     FROM table2 t2,
     13                          table1 t1
     14                    WHERE t1.prd_id        = t2.prd_id
     15                      AND t1.prd_ver       = t2.prd_ver
     16                      AND t1.py_id         = t2.py_id
     17                      AND t1.typ_id        = t2.typ_id
     18*                     AND t3.common_column = t2.common_column)
    SQL> /
    
    3 rows updated.
    
    SQL> select * from table3;
    
    COMMON_COL COLUMN_TO_
    ---------- ----------
    A          VALUE1
    B          VALUE1
    C          VALUE2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My issue is not able to render the chart in .tpl file. The following
I am not able to understand few things on the Garbage collection. Firstly, how
I'm not able to understand the difference between Thread vs ThreadPool. Consider i've to
I've been trying to understand why the following code gives me a bad pointer
I am not able to compile the following code. I run it in a
I am not able to understand what is the function of this line in
I am not able to access localhost https pages in firefox3. It gave the
I am not able to use the breakpoint in Studio with Javascript. I'm able
Why are we not able to override an instance variable of a super class
I am not able to figure out this simple thing in ASP.NET MVC: I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.