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

The Archive Base Latest Questions

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

I have three tables: TableA +——-+——–+——–+ | id_a | name | total | +——-+——–+——–+

  • 0

I have three tables:

TableA

+-------+--------+--------+
| id_a  | name   | total  |
+-------+--------+--------+
|    1  | Andrew |        |
|    2  | Jhon   |        |
+-------+--------+--------+

TableB

+-------+--------+--------+--------+
| id_b  | id_a   | amount | id_c   |
+-------+--------+--------+--------+
|    1  | 1      |    5   | 1      |
|    2  | 1      |    1   | 2      |
+-------+--------+--------+--------+

TableC

+-------+--------+
| id_c  | status |
+-------+--------+
|    1  | 1      |
|    2  | 0      |
+-------+--------+

So what I need to do is to count a total sum of amounts from TableB where id_a = (1 or my posted id) AND where status of id_c is 1 or 0 and set it into the TableA in total column, for the data in the tables I’ve posted above the field total in a TableA where id_a = 1 will contains a 6 value.

I’m trying to go in my query through this way:

UPDATE TableA SET total=(SELECT SUM(amount) as sum FROM TableB WHERE id_a = 1 GROUP BY(sum))

but this is way is wrong ( I think ). How would be nice query to this?

  • 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-17T09:21:34+00:00Added an answer on June 17, 2026 at 9:21 am

    You can use an INNER JOIN between TableB and TableC in your inner SELECT.

    UPDATE TableA SET
        total=(
            SELECT SUM(amount) FROM TableB
                               INNER JOIN TableC ON TableB.id_c = TableC.id_c
            WHERE id_a = 1 AND (status = 1 OR status = 0)
            GROUP BY id_a
        )
    WHERE id_a = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables, table one (tableA) containing users data like name and email,
I have three tables, tableA (id, A), tableB (id,B) and tableC (id,C). id is
I have three SQL tables: TableA, TableB, and TableC TableA is a primary key
Basically, I have three tables, lets call them TableA, TableB and TableC. Table A
I have a tag table and three tableA , tableB , tableC tables that
Assuming I have three tables : TableA (key, value) TableB (key, value) TableC (key,
I have 3 tables with the following columns TableA Name Description ..... TableB Name
I have four tables TableA: id1 id2 id3 value TableB: id1 desc TableC: id2
I have this three tables: products TABLE: id:integer name:string features TABLE: id:integer name:string features_products
I have three tables: game columns: id | name (eg. 1 | Halo) own

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.