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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:19:14+00:00 2026-06-06T23:19:14+00:00

I have 3 table stock,inward,issue Stock table’s columns and data : part_no | part_name

  • 0

I have 3 table stock,inward,issue

Stock table’s columns and data :

part_no | part_name | totalqty
10100        ciol      30
112233       abc       20
123456       coper      50

inward table :

part_no | qty
123456   10
123456   20
10100    20
112233   15
10100    25

issue table :

part_no | qty
112233   20
112233   15
123456   10
112233   25
10100    40
10100    20

my desired output :

part_no | part_name  |inwardQty |issueQty
10100      coil         45     60
112233     abc          15     60
123456     coper        30     10

following is the query i have written,but not giving my desired output

select s.part_no,s.part_name,sum(i.qty) as inwardQty,sum(p.qty)as issueQty 
from stock s 
left join inward i on s.part_no = i.part_no
left join issue p on s.part_no = p.part_no 
group by 
    s.part_no,s.part_name

getting following output by this query :

part_no | part_name  |inwardQty |issueQty
10100      coil         90     120
112233     abc          45     60
123456     coper        30     20
  • 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-06T23:19:15+00:00Added an answer on June 6, 2026 at 11:19 pm

    The problem is that you’re matching every row for inward with every row for issue, for which they’re dealing with the same part. I think subqueries would be best here:

    select s.part_no,s.part_name,i.qty as inwardQty,p.qty as issueQty 
    from stock s 
    left join
        (select part_no,sum(qty) as qty from inward group by part_no) i on s.part_no = i.part_no
    left join
        (select part_no,sum(qty) as qty from issue group by part_no) p on s.part_no = p.part_no 
    

    So now, there’s only one (or zero) rows to join in each of the joins, and you don’t get a cartesian product.

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

Sidebar

Related Questions

I have a table of data for a particular stock that contains every single
I have a MySql table with daily stock market data in the following order:
need help/guide for sql select query, I have 2 table stock and stock_history, in
I have a table called Stock and another called Listed, within the Stock Table
I have a MySql table containing stock quotes (stock_symbol, quote_date, open_price, high_price, low_price, close_price)
I have a table that contains the stock. It's legacy database and the stock
I have 2 tables like this: Stock Table product_id bigint(20) qty float Sales Table
I'm trying to write a simple stock check program, and I have a Table
I have a groupby and sum table that I use to display current stock
I have a stock table and I would like to create a report that

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.