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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:48:17+00:00 2026-06-11T09:48:17+00:00

I have a table like this: A ID_A ID_1 ID_2 1 1 (null) 2

  • 0

I have a table like this:

A
ID_A    ID_1   ID_2
1       1      (null)
2       3      (null)
3       7      (null)

B
ID_B    ID_1   ID_2
1       (null) 2
2       (null) 4
3       (null) 6

REF     
ID_A    ID_B
1       2
3       1

According to the ref table, the object with an ID_A of 2 is the same object as an ID_B of 1.

Therefore, I should be able to update the table this way:

A
ID_A    ID_1   ID_2
1       1      4
2       3      (null)
3       7      2

Indeed, you get that result if you do this query:

select
  A.ID_A, B.ID_1, C.ID_2
from
  A, B, REF
where
  A.ID_A = REF.ID_A
  AND REF.ID_B = B.ID_B

(actually you lose the null row because it’s an inner join, but that’s not the point.)

What I am completely unable to do is update A with this new information! I either get “single-row subquery returns more than one row” with an update or the lovely result that my query is non-deterministic with a merge.

Given that I really do have the three tables as I’ve shown, how can I write a query to update id_2 correctly?
;

  • 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-11T09:48:19+00:00Added an answer on June 11, 2026 at 9:48 am
    merge into A w
    using(select a.id_a
               , b.id_2
           from a 
           join rf on (a.id_a = rf.id_a)
           join b   on (b.id_b = rf.id_b) 
         ) q
      on (q.id_a = w.id_a )
    when matched then
      update 
         set w.id_2 = q.id_2
    

    SQL Fiddle

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

Sidebar

Related Questions

I have table design like this: id_a int(10) NO PRI id_b int(10) NO PRI
I have a table like this ID Name IsDeleted 1 Yogesh Null 2 Goldy
I have an SQL table like this ID | ParentID 1 | null 2
I have a table like this: ID country ------------- 1 US 2 Japan 3
I have a table that looks like this: id count 1 100 2 50
I have a table which have schema like this id name 1 jack 2
I have a table like this gems ---------- id, color 1 , green 2
i have a table like this one: -------------------------------- id | name -------------------------------- 1 |
I have a table like this one: id group value 1 GROUP A 0.641028
We have a table like this: id mid mult tr result ---------------------------- 1 1

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.