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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:33:25+00:00 2026-06-09T07:33:25+00:00

I sum up the rows of two columns in two tables i.e. something like

  • 0

I sum up the rows of two columns in two tables i.e. something like this:

SUM( tableA.age ) + sum( tableB.age) as 'Total Ages'

But in some cases the result of table A is null while result of table B is not. In this case I get as a total result null although it is something like “NULL + 45” which is not null actually. Therefore I thought it would be a good idea to use the if clause of the sql syntax. But it does not work I get an error when trying to do the following:

IF SUM( tableA.age ) IS NULL THEN 0 ELSE  SUM( tableA.age ) END IF + IF SUM( tableB.age ) IS NULL THEN 0 ELSE  SUM( tableB.age ) END IF

How would I do that in a proper way?

  • 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-09T07:33:27+00:00Added an answer on June 9, 2026 at 7:33 am

    Simply use IFNULL() when you feel the field has NULL value.

     SUM(IFNULL(tableA.age,0) ) 
    

    You can use this MYSQL function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables containing three columns containing the same types of information(id, attributes,
I have two data.tables in R which have an identical set of columns. They
I need to change the sum(decode()) expressions that are like SUM(Decode(vcon.WAGON_TYPE_CODE,'MS',1,0)) to something that
I have a two dimensional array, which represents columns and rows of data. I
What I have are two tables: mark_notifications mark_notifications_options The mark_notifications table contains rows of
How do I calculate Sum of two rows in DataTable which is of type
I would like to merge two data frames, but do not want to duplicate
I would like to compare two lists (two rows of a data frame) and
I have two tables, a Countries table and a Weather table. I would like
How to calculate weekly sum (sum of last 7 rows printed in 7th row)

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.