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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:44:41+00:00 2026-06-01T19:44:41+00:00

I have following table structure, with many tables like this: data_1: +——-+——–+——-+ | views

  • 0

I have following table structure, with many tables like this:

data_1:
+-------+--------+-------+
| views | clicks | date  |
+-------+--------+-------+
|    29 |     1  | ..... |
|   458 |     9  | ..... |
+-------+--------+-------+ 
....

data_43:
+-------+--------+-------+
| views | clicks | date  |
+-------+--------+-------+
|     0 |     0  | ..... |
|     0 |     0  | ..... |
+-------+--------+-------+ 
...

My question here is, how can I get all the sum values in one query?

I tried it with a simple join:

mysql> SELECT SUM(t1.views)  data_1_views,
              SUM(t1.clicks) data_1_clicks,
              SUM(t2.views)  data_43_views,
              SUM(t2.clicks) data_43_clicks
       FROM data_1 t1, data_43 t2;

But my result isn’t what I expected:

+--------------+---------------+---------------+----------------+
| data_1_views | data_1_clicks | data_43_views | data_43_clicks |
+--------------+---------------+---------------+----------------+
|         NULL |          NULL |          NULL |           NULL |
+--------------+---------------+---------------+----------------+

I expected it to be:

+--------------+---------------+---------------+----------------+
| data_1_views | data_1_clicks | data_43_views | data_43_clicks |
+--------------+---------------+---------------+----------------+
|         487  |          10   |             0 |              0 |
+--------------+---------------+---------------+----------------+

Anyone here who can help me with this query?
I am also interested if this is more performant than doing all this stuff in multiple queries

  • 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-01T19:44:43+00:00Added an answer on June 1, 2026 at 7:44 pm

    In this case multiple queries are fine especially if you are grouping many rows. There is virtually no benefit (and actually potential bugs) lumping these two tables in one query.
    I would just make two queries

    SELECT SUM(t1.views) data_1_views, SUM(t1.clicks) data_1_clicks
    FROM data_1 t1 
    
    SELECT SUM(t2.views) data_43_views, SUM(t2.clicks) data_43_clicks
    FROM data_43 t2; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have the following table structure CREATE TABLE `table` ( `id` int(11) NOT NULL
I have the following table structure (in MySQL): DocID, Code, IsDup, DopOf , where
I have the following table structure. A | B | C I wish to
I have the following table structure, which is imported into an Entity Framework project:
I have the following MySQL table structure: num field company phone website 1 Gas
I have no control over database schema and have the following (simplified) table structure:
I have table with following structure and test records: +--------+--------+---------+ | vid | number
I have table with following structure Whenever user click on checkbook and click on
I have table with following structure and records. table t1 +------+-------------+---------------------+ | name |

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.