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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:56:37+00:00 2026-05-25T09:56:37+00:00

I have a problem trying to figure out how to create a query… Let’s

  • 0

I have a problem trying to figure out how to create a query…
Let’s assume we have 2 tables like these:

TABLE A
id - box1_id - box1count - box2_id - box2_count
1  - 1       - 100       - 2       - 111
2  - 2       - 222       - NULL    - NULL
3  - 2       - 333       - 3       - 1000

TABLE B
id_box - box_Name
1      - HELLO
2      - TEST
3      - HELP

I want to write a query that retrive something like that:

id_box - box_Name - box_sumcount
1      - HELLO    - 100
2      - TEST     - 666
3      - HELP     - 1000

box_sumcount is the sum of box1_count or box2_count based on box1_id or box2_id are equal to id_box…

  • 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-25T09:56:38+00:00Added an answer on May 25, 2026 at 9:56 am
    SELECT TableB.id_Box,TableB.Boxname, Sum(BC.BoxCount)
    FROM TableB
    INNER JOIN 
      (SELECT box1_id as boxid, box1Count as boxCount
       UNION 
       SELECT box2_id as boxid, box2Count as boxCount
      ) BC
     ON (TableB.id_box=BC.Boxid)
     GROUP BY TableB.id_Box, TableB.Boxname
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to figure this problem out without asking for help, but
For example I have the following tables resulting from: CREATE TABLE A (Id int,
We're currently stuck trying to make a simple (?) SQL query. We have these
Trying to figure out how to build a query in CakePHP where I can
I'm trying to figure out how to accomplish the following: User can have many
Hey, I've got a bit of a problem right now trying to figure out
I'm new to Entity Framework and am trying to figure things out. I have
I have been working on an application, and was trying to figure out why
Say I have a table like so: CREATE TABLE big_table (UUID varchar(32) not null,
Ok, I have been staring at this for hours trying to figure out what's

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.