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 7506631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:19:21+00:00 2026-05-29T22:19:21+00:00

I have two tables with a one-to-one relationship. Table1 has a composite primary key

  • 0

I have two tables with a one-to-one relationship. Table1 has a composite primary key consisting of about 4 columns. Table2’s foreign key is set to Table1’s primary key.

When I try the following UPDATE clause, I am getting an error:

UPDATE Table2
SET column1 = fakeTable.c1
FROM Table2 INNER JOIN
    (
        SELECT Table1.primaryKey
        , (Table1.column3 + Table1.column4) AS c1
        FROM Table1
    ) AS c1
ON Table2.foreignKey = fakeTable.primaryKey

Am I not allowed to reference keys as if they are columns?

  • 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-29T22:19:21+00:00Added an answer on May 29, 2026 at 10:19 pm

    No, you need to list all the fields individually. But you can avoid the sub-query that you have…

    UPDATE
      Table2
    SET
      column1 = Table1.column3 + Table1.column4
    FROM
      Table2
    INNER JOIN
      Table1
        ON  Table2.foreignKey1 = Table1.primaryKey1
        AND Table2.foreignKey2 = Table1.primaryKey2
        AND Table2.foreignKey3 = Table1.primaryKey3
        AND Table2.foreignKey4 = Table1.primaryKey4
    

    EDIT

    Response to comment:
    – I thought the whole point of keys was to avoid having to concatenate columns!

    Keys aren’t a time saving device, they’re data integrity devices.

    A primary key is a unique identifier. I can be a composite or not, but the important thing is that it is unique and not nullable.

    A foreign key is also a data integrity device. It ensure that if data refers to something in another table, it actually must exist in that other table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables one has a three column composite key. The other needs
I have two tables: invoice and charges, with a one-to-many relationship. (simplified) invoice has:
If I have two tables, Person PhoneNumbers As it has a one-to-many relationship, do
I have two tables, Table_A and Table_B. Table_A has a one-to-many relationship with Table_B.
So I have two tables, article and comments (which has one-to-many relationship (1 article
I have a one to many relationship between two tables. The many table contains
I have two tables. One (Widgets) has a list of widgets (ID, widget_name, color,
I have two tables, one is a table of forum threads. It has a
I have two tables - 'business' and 'business_contacts'. The business_contact table has a many-to-one
In MySQL, I have two tables with a 1:n relationship. Table items has products,

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.