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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:10:57+00:00 2026-06-13T23:10:57+00:00

I have three tables linked each other. mysql> select * from tablea; +—-+——–+ |

  • 0

I have three tables linked each other.

mysql> select * from tablea;
+----+--------+
| id | name   |
+----+--------+
|  1 | Item 1 |
|  2 | Item 2 |
+----+--------+
2 rows in set (0.00 sec)

mysql> select * from tableb;
+----+------+----------+
| id | Aid  | name     |
+----+------+----------+
|  1 |    1 | B Item 1 |
|  2 |    2 | B Item 2 |
|  3 |    1 | B Item 3 |
+----+------+----------+
3 rows in set (0.00 sec)

mysql> select * from tablec;
+----+------+----------+-------+
| id | Bid  | name     | value |
+----+------+----------+-------+
|  1 |    1 | C Item 1 |    10 |
|  2 |    2 | C Item 2 |    20 |
|  3 |    1 | C Item 3 |    15 |
|  4 |    2 | C Item 4 |     5 |
|  5 |    3 | C Item 5 |    12 |
+----+------+----------+-------+
5 rows in set (0.00 sec)

TableA is linked to TableB with Aid, TableC is linked with TableB with Bid.

What I want is the id of tableA and the sum of values of all the TableC items comes under it.

The result set I expect for the above example is

+-----------+--------+
| tablea.id | sum    |
+-----------+--------+
|         1 |     37 |
|         2 |     25 |
+-----------+--------+
  • 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-13T23:10:58+00:00Added an answer on June 13, 2026 at 11:10 pm
    SELECT  a.ID, SUM(c.value) totalValue
    FROM    tablea a
            INNER JOIN tableb b
                On a.ID = b.AID
            INNER JOIN tablec c
                ON b.ID = c.BID
    GROUP BY a.ID
    

    if there’s a possibility that ID from tableA doesn’t exist on other tables and you also want to show their result, use LEFT JOIN instead

    SELECT  a.ID, COALESCE(SUM(c.value), 0) totalValue
    FROM    tablea a
            LEFT JOIN tableb b
                On a.ID = b.AID
            LEFT JOIN tablec c
                ON b.ID = c.BID
    GROUP BY a.ID
    
    • SQLFiddle Demo for both queries
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL query that: gets data from three tables linked by unique
First, the topic. I have three models, which are linked between each other with
I have three tables in MySQL that are related, yet not technically linked to
I have three database tables: users emails invitations Emails are linked to users by
I have three tables of data: table: cars [10,000 rows] table: planes [2,000 rows]
I have three tables in a Mysql database - countries, cities and hotels. Their
I have a table called Request. Other tables are linked to the Request table
This has been driving me mad. I have three tables: items ID name type
I have three tables. I have to retrieve the data using Linq statement. My
I have three tables (individuals, groups & recordlabels) and want use the information between

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.