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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:03:59+00:00 2026-06-10T12:03:59+00:00

I have a table to be updated using records of another table and I

  • 0

I have a table to be updated using records of another table and I am doing this to bring over information from one system (database) to another.
The scenario is bit complex, but I desperately need help :-s

There are 3 tables – component , scan and stage_link

component

component_id  stage_id
------------  --------
1              NULL
2              NULL
3              NULL
4              NULL
5              NULL

scan

scan_id  component_id  scanner_id           date_scanned
-------  ------------  ----------  -----------------------
 1         1           scanner_a    2012-01-01 07:25:15.125
 2         1           scanner_b    2012-01-02 08:14:05.456
 3         2           scanner_a    2012-01-01 12:05:45.465
 4         3           scanner_a    2012-01-01 19:45:12.536
 5         1           scanner_c    2012-01-03 23:33:54.243
 6         2           scanner_b    2012-01-02 11:59:12.545

stage_link

stage_link_id  scanner_id  stage_id
    -------     ----------  ----------  
       1         scanner_a    1   
       2         scanner_b    1    
       3         scanner_c    2    
       4         scanner_d    2    
       5         scanner_e    2   
       6         scanner_f    3  

I need to update the table component and set the field stage_id according to the latest scan. Each scan takes the component to a stage according to the scanner involved. I have written the following query in order to update the table component, but it throws an error saying;

Subquery returned more than 1 value. This is not permitted when the subquery follows '='

The query is;

UPDATE component
SET stage_id = (select stage_id
                from(
                    select scn.scanner_id, sl.stage_id
                    from scan scn
                    INNER JOIN stage_link sl ON scn.scanner_id = sl.scanner_id
                    where scn.date_scanned = (  select temp_a.max_date 
                                                from (  SELECT x.component_id, MAX(x.date_scanned) as max_date
                                                        FROM scan x
                                                        where component_id = x.component_id 
                                                        GROUP BY x.component_id
                                                      ) as temp_a
                                                where component_id = temp_a.component_id)
                    ) as temp_b
                )

I am working on MS SQL Server and want to sort this out using no PHP or any other language.

I have tried for a day to make this work but still didn’t get a way to make this work. Any help would be highly appreciated!

Thank you very much in advance 🙂

  • 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-10T12:04:01+00:00Added an answer on June 10, 2026 at 12:04 pm

    Check this out without using correlated subqueries:

    UPDATE  Com
    SET     stage_id = Temp4.stage_id
    FROM    dbo.component Com
            INNER JOIN 
            ( 
                SELECT Temp2.component_id ,SL.stage_id
                FROM   dbo.stage_link SL
                INNER JOIN (
                                SELECT component_id ,scanner_id
                                FROM   scan
                                WHERE  date_scanned IN (
                                    SELECT  MaxScanDate
                                    FROM    
                                    ( 
                                        SELECT component_id , MAX(date_scanned) MaxScanDate
                                        FROM scan
                                        GROUP BY component_id
                                    ) Temp 
                                )
                            ) Temp2 ON Temp2.scanner_id = SL.scanner_id
            ) Temp4 ON Com.component_id = Temp4.component_id
    

    The output:

    component_id stage_id
    ------------ -----------
    1            2
    2            1
    3            1
    4            NULL
    5            NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table of frequently updated information. This is presented using a container
I'm inserting records from one table into another table using a select statement. The
I have a table with records from a database which is dynamically filled. <table>
I am using Microsoft SQL Server. I have a Table which had been updated
I have a stored procedure that updates a table using linq, eg: (this is
UPDATED: I have some table with sync_numbers, like this: --------------------- id | sync_number ---------------------
I have a innoDB table which records online users. It gets updated on every
I have two very large enterprise tables in an Oracle 10g database. One table
I have a table, say STUDENTS, that is related one-to-many to another table, CLASSES.
In a database I have less than 200,000 records in a table, and in

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.