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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:58:05+00:00 2026-06-14T14:58:05+00:00

Id Item ————– 1 ItemA 2 ItemB 3 ItemC itemid Price —————- 1 4

  • 0
Id       Item
--------------
1        ItemA 
2        ItemB
3        ItemC

itemid     Price
----------------
1          4
1          3
1          9
2          2
2          4
2          3

How I can select with sum from 2 tables? Like as:

ItemA 16
ItemB 9
ItemC 0
  • 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-14T14:58:06+00:00Added an answer on June 14, 2026 at 2:58 pm

    You can JOIN the table using a LEFT JOIN and apply an aggregate function SUM() to the price field:

    select t1.item, IsNull(sum(t2.price), 0) total
    from table1 t1
    left join table2 t2
      on t1.id = t2.itemid
    group by t1.item
    

    See SQL Fiddle with Demo

    The LEFT JOIN will allow for the records not in the second table to be included in the final result. I added the IsNull() to the sum() to replace any null values with a zero.

    Result:

    |  ITEM | TOTAL |
    -----------------
    | ItemA |    16 |
    | ItemB |     9 |
    | ItemC |     0 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from item in range where item % 2 ==0 select i ; extension methods
from item in db.Items join ci in db.ChainStoreItems on item.ItemId equals ci.ItemId where ci.ChainStoreId
$db_item = $wpdb->get_results($wpdb->prepare( SELECT * FROM wp_wowhead_items WHERE name LIKE %s, %. Hello .
Tables: Item Id Keyword Id Keyword ItemKeyword ItemId KeywordId SequenceNumber for searching items via
I have three tables: Item ItemCategories Categories If ItemCategories contain: id itemID categoryID How
My item template in gridview is marked up like this. Where do I add
I have product item webpages located in /product/items/*.html?id=12345&ref=54321 and I would like the webpages
Item can contain multiple Sizes . When I try to add new size to
Item 2 of the Joel Test is Can you make a build in one
SELECT item_name from items WHERE item_id = $var; I tried: $var = 001 ||

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.