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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:29:08+00:00 2026-06-01T13:29:08+00:00

I am trying to run a rather convoluted query. Two tables are out of

  • 0

I am trying to run a rather convoluted query. Two tables are out of sync. In one step of the processing, a 16 digit value is copied from one table to the other, and is getting truncated to just 10 digits.

I’m using a few pieces of information to copy the full 16 digit number over. I’m trying to find anywhere where the 10 digit value matches the first 10 digits of the 16 digit value, and three other pieces of information in these two tables match. Combined, they give almost 100% certainty that we have a unique entry. This is the current iteration of my query:

UPDATE DB1.TABLE1
SET ID =
(
SELECT b.ID
FROM DB2.TABLE1 b
INNER DB1.TABLE1 a 
ON left(b.ID, 10) = a.ID
WHERE len(a.ID) = 10
AND a.STORE = b.STORE
AND a.DOCTYPE = b.DOCTYPE
AND a.DOCDATE = b.DOCDATE
)

The problem is, it’s telling me the subquery is returning multiple results. But I want multiple results. I tried adding another WHERE statement after the parenthesis, and duplicating the last four lines of the subquery, but that’s not working either. I also tried using WHERE EXISTS and duplicating the entire SELECT statement, but that gives em the multiple results error as well. What am I missing here?

  • 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-01T13:29:10+00:00Added an answer on June 1, 2026 at 1:29 pm

    Your statement is attempting to update every row in DB1.TABLE1 to what’s returned by the subquery. Not only is that not what you want, but the statement fails because the subquery is returning multiple values.

    What you need to do is correlate the two tables as part of the update statement, like this:

    UPDATE DB1.TABLE1
    SET ID = b.ID
    FROM DB1.TABLE1 a
      INNER JOIN DB2.TABLE1 b
      ON left(b.ID, 10) = a.ID
        AND a.STORE = b.STORE
        AND a.DOCTYPE = b.DOCTYPE
        AND a.DOCDATE = b.DOCDATE
    WHERE len(a.ID) = 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run a rather simple query, but it seems to return
Situation: I'm trying run an https store (xcart) under one domain secure.example.com and I
I'm trying to run jstack command on my java application. Application is rather big,
I am trying to run what I thought was a rather simple parameterized insert
I'm working with a rather large query string(~30+ parameters) and am trying to pass
I'm trying to run a sql script using H2's runscript. One of the table
I am trying to run an application on multiple (~20) Unix servers. Rather than
I am trying to run this query however it's only outputting results of categories
I am trying to work out how to develop a reasonably scalable batch-processing framework
I am trying run a program from a qmake .pro file which modifies the

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.