0

This is my query.

 SELECT dr_trans_dtl.dr_ID, jo_trans_dtl.qty 
 FROM dr_trans_dtl 
 LEFT JOIN jo_trans_dtl ON dr_trans_dtl.jo_no = jo_trans_dtl.jo_no 
 WHERE dr_trans_dtl.dr_no = '3329' GROUP BY dr_trans_dtl.dr_ID

Here is the actual result:

enter image description here

What I wanted is the qty should be like this (500,40,1). Because that is the data in jo_trans_dtl.

21
  • GROUP BY could be GROUP BY dr_trans_dtl.dr_ID,jo_trans_dtl.qty Commented Dec 5, 2018 at 6:42
  • The result repeats two field/column (dr_ID,qty) Commented Dec 5, 2018 at 6:52
  • Give your expected output and give your current data that you are get. Commented Dec 5, 2018 at 6:56
  • 1
    Without seeing any sample data it's hard to be sure but you could probably remove the GROUP BY dr_trans_dtl.dr_ID and change SELECT dr_trans_dtl.dr_ID, jo_trans_dtl.qty to SELECT DISTINCT dr_trans_dtl.dr_ID, jo_trans_dtl.qty Commented Dec 5, 2018 at 6:58
  • Please see pic imgur.com/a/vNsW6NM Commented Dec 5, 2018 at 7:11

1 Answer 1

1

It seems you need aggregate function as you used group by

 SELECT dr_trans_dtl.dr_ID,sum(jo_trans_dtl.qty) as qty
 FROM dr_trans_dtl 
 JOIN jo_trans_dtl ON dr_trans_dtl.jo_no = jo_trans_dtl.jo_no 
 WHERE dr_trans_dtl.dr_no = '3329'
 GROUP BY dr_trans_dtl.dr_ID
Sign up to request clarification or add additional context in comments.

2 Comments

The result is dr_ID | qty 9074 | 509 9075 | 509 9076 | 509 It should be dr_ID | qty 9074 | 500 9075 | 40 9076 | 1 Because (500,40,1) are in the jo_trans_dtl.
@Jonathan share your both table data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.