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

  • Home
  • SEARCH
  • 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 8135161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:19:35+00:00 2026-06-06T10:19:35+00:00

I have two tables with identical schema. Let’s name them TestTable and TestTableTemp .

  • 0

I have two tables with identical schema. Let’s name them TestTable and TestTableTemp. I need to copy just two columns from TestTableTemp to TestTable without disrupting other data. The rows in TestTable are a subset of those in TestTableTemp. Let’s say the columns that I need to copy are named Column1 and Column2 and that they have identical primary keys reference by column primaryKey.


In mysql I believe this could be done as such or something similar:

UPDATE TestTable, TestTableTemp
SET TestTable.Column1 = TestTableTemp.Column1, TestTable.Column2 = TestTableTemp.Column2
WHERE TestTable.primaryKey = TestTableTemp.primaryKey

Sqlite does not allow for multiple tables to be defined on the update statement as can been seen in their reference data here: http://www.sqlite.org/lang_update.html

The best I could come up with is such:

UPDATE TestTable SET
Column1 = (select TestTableTemp.Column1 from TestTableTemp, TestTable where TestTable.primaryKey = TestTableTemp.primaryKey),
Column2 = (select TestTableTemp.Column2 from TestTableTemp, TestTable where TestTable.primaryKey = TestTableTemp.primaryKey) 
WHERE EXISTS(select * from TestTableTemp where TestTable.primaryKey = TestTableTemp.primaryKey"

This gives me a syntax error near “.” I am guessing this is because I cannot reference TestTable in the scalar expressions.

Can anyone point me in the right direction? Any help is much appreciated.

EDIT:

I cleaned up the second query a bit. It seems to just set the Column1 and Column2 to the first row from that column from TestTableTemp.

  • 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-06-06T10:19:36+00:00Added an answer on June 6, 2026 at 10:19 am

    Your original query for comparison:

    UPDATE TestTable, TestTableTemp
       SET TestTable.Column1 = TestTableTemp.Column1
         , TestTable.Column2 = TestTableTemp.Column2
     WHERE TestTable.primaryKey = TestTableTemp.primaryKey
    

    Here is the working query (I just slightly changed your version):

    http://sqlfiddle.com/#!5/f3a19/9

    UPDATE TestTable
    SET
    
      Column1 = ( SELECT TestTableTemp.Column1
                  FROM   TestTableTemp
                  WHERE  TestTableTemp.primaryKey = TestTable.primaryKey )
    
     ,Column2 = ( SELECT TestTableTemp.Column2
                  FROM   TestTableTemp
                  WHERE  TestTableTemp.primaryKey = TestTable.primaryKey )
    
    WHERE EXISTS( SELECT NULL
                  FROM   TestTableTemp
                  WHERE  TestTableTemp.primaryKey = TestTable.primaryKey )
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two identical tables and need to copy rows from table to another.
I have two tables TABLE1 and TABLE2 with identical structures. I need a trigger
Let's say I have two identical tables, A and B, with the row x.
I have two tables, projects and archive with identical columns. As you understand, I
I have two tables that have identical columns. One table houses imported data, the
I have a two tables. values inside them are not identical, but most of
I have two tables with one identical column name, but different data. I want
I have two tables with identical schema in SQL Server 2008 R2. If I
I have two SQLSever instances, each of them have an identical schema. One is
I have two identical SQL Server tables ( SOURCE and DESTINATION ) with lots

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.