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

  • Home
  • SEARCH
  • 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 6090119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:10:38+00:00 2026-05-23T12:10:38+00:00

I know this question might seem a little basic stuff but I want to

  • 0

I know this question might seem a little basic stuff but I want to make sure I get the right syntax because this line of code will run often:

I want to sum columns A, B and C of table “alphabet” for all rows which have an id included in my IN clause.

This is how I would do it but I’d like a confirmation if possible:

SELECT SUM(A + B + C) as "subtotal" FROM alphabet WHERE id IN ('1','5','378');
  • 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-23T12:10:39+00:00Added an answer on May 23, 2026 at 12:10 pm

    If id is not a string, you shouldn’t quote those values.

    SELECT SUM(A + B + C) as "subtotal" FROM alphabet WHERE id IN (1,5,378);
    

    This should work, but may may have one non-obvious consequence. If any row has A not null and one of the others null, that row will drop out of the summation because a null plus anything else is null, and nulls are ignored by the SUM operator. Thus it may be safer to write:

    SELECT SUM(A) + SUM(B) + SUM(C) as "subtotal" FROM alphabet WHERE id IN (1,5,378);
    

    This suffers from the same potential problem, but it is less likely to happen because an entire column would have to be null. There are various dialect specific ways to defend against that problem if you are still concerned. The most portable is the painfully verbose:

    SELECT SUM(
          CASE
            WHEN A IS NULL
            THEN 0
            ELSE A
          END
          +
          CASE
            WHEN B IS NULL
            THEN 0
            ELSE B
          END
          +
          CASE
            WHEN c IS NULL
            THEN 0
            ELSE C
          END
        ) as "subtotal"
    FROM alphabet
    WHERE id IN (1,5,378);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question might sound a little cheesy but this is the first
To a person skilled in programming, I know this question might seem ridiculous, but
This might seem like a simple question but Id like to know the fastest
I know this might seem a simple question, but with all the WMD versions
I know this question isn't directly programming related, but since I want to be
This question might seem very specific but I am in need of some ideas
This might seem like a weird question, but bear with me. I'd like to
this might sound like a daft question but I can't seem to find a
This might seem a really bizarre question, but just go with me for a
I know this question might be considered better on Stack UI, but I wanted

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.