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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:31:42+00:00 2026-05-14T21:31:42+00:00

I would like a query that will show a sum of columns with a

  • 0

I would like a query that will show a sum of columns with a default value for missing data. For example assume I have a table as follows:

type_lookup:

id name
-----------
1  self
2  manager
3  peer

And a table as follows

data:

id  type_lookup_id value
--------------------------
1   1              1
2   1              4
3   2              9
4   2              1
5   2              9
6   1              5
7   2              6
8   1              2
9   1              1

After running a query I would like a result set as follows:

type_lookup_id   value
----------------------
1                13
2                25
3                0

I would like all rows in type_lookup table to be included in the result set – even if they don’t appear in the data table.

  • 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-14T21:31:42+00:00Added an answer on May 14, 2026 at 9:31 pm

    It’s a bit hard to read your data layout, but something like the following should do the trick:

    SELECT tl.type_lookup_id, tl.name, sum(da.type_lookup_id) how_much
     from type_lookup tl
      left outer join data da
       on da.type_lookup_id = tl.type_lookup_id
     group by tl.type_lookup_id, tl.name
     order by tl.type_lookup_id
    

    [EDIT]
    …subsequently edited by changing count() to sum().

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

Sidebar

Related Questions

I would like to build a query that will pull the number of rows
I would like to create a query that returns rows in the following format:
I would like to run a (extensive) query that produces one line of XML.
I would like to delete all the rows found by that query: SELECT cart_abandon.*
I have two different tables, lead and click. I would like to query MySQL
I have a stock table and I would like to create a report that
I have a query which I would like to tweak little bit to display
I have a table that looks like expires | value ------------------- 2011-06-15 | 15
I would like to have a search box integrated into a nav bar that
below I have a query that will get the most common user agents for

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.