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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:41:58+00:00 2026-05-27T12:41:58+00:00

I have a table dutyrecord which stores multiple user working hours (subtotal) and a

  • 0

I have a table dutyrecord which stores multiple user working hours (subtotal)
and a UserID (volunteerID). With the following selecting statement I am about to set a total hours for each UserID:

SELECT
dutyrecord.VolunteerID,
SEC_TO_TIME( SUM( TIME_TO_SEC( SubTotal ) ) ) AS total
FROM
volunteerinfo
INNER JOIN
dutyrecord ON
( volunteerinfo.VolunteerID = dutyrecord.VolunteerID )
GROUP BY
dutyrecord.VolunteerID

Could I combine an update statement with a select to update total hours to each user? I tried something like and some other method with no luck:

UPDATE volunteerinfo 
SET 
TotalHours = 
( 
SELECT dutyrecord.VolunteerID , 
SEC_TO_TIME( SUM( TIME_TO_SEC( SubTotal ) ) ) AS total
FROM 
volunteerinfo
INNER JOIN 
dutyrecord ON ( volunteerinfo.VolunteerID = dutyrecord.VolunteerID )
GROUP BY 
dutyrecord.VolunteerID 
)
WHERE 
volunteerinfo.VolunteerID = dutyrecord.VolunteerID`

Can anyone give me a hand on this?

UPDATE
Sorry a few try and other examples I figure out the answer and a more clear way to ask my question.
To clear my question: Can I combine this process into one since I wants to make this process language independent? (I just carry 1 SQL statement in different perform.)

  • First, I select a table to give me the Sum of working hours for each person

    SELECT VolunteerID, SEC_TO_TIME( SUM( TIME_TO_SEC( SubTotal ) ) ) AS total
    FROM dutyrecord
    GROUP BY VolunteerID

    e.g. ID: 10001, 1:00:02 ID: 2001, 10:00:34 ….

  • After, I want to update the result (total) into another table according to their ID

    update Volunteerinfo
    set Volunteerinfo.totalhours = dutyrecord.total
    where Volunteerinfo.VolunteerID = dutyrecord.VolunteerID

  • 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-27T12:41:58+00:00Added an answer on May 27, 2026 at 12:41 pm

    My answer to this is to first join both tables together then the update and select statement will work in one row. please also comment me if inner join or other ways will increase the performance of this query.

    update volunteerinfo I 
     join
      (SELECT VolunteerID, SEC_TO_TIME( SUM( TIME_TO_SEC( SubTotal ) ) ) AS total
    FROM dutyrecord
    GROUP BY VolunteerID) R on R.volunteerid = I.volunteerid
    set I.totalhours = R.total
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table in my database which has fields of ID,NAME,CONTEXT. I am showing
I have table the following data structure in SQL Server: ID Date Allocation 1,
I have table view which is populated from an array grabbed from a url.
I have table which will only contain information about files, so, as the file
I have table named Table X which contains some names and their corresponding age,
I have table of user actions, each having a user associated, a type, and
I have table view which is showing list of files to download. When I
I Have Table with multiple columns and rows, Example, <table> <thead> <tr> <th>Head 1</th>
I have table with 3 columns: id (of person), city (which person visited) and
I have table named as contacts which has nearly 1.2 million records we use

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.