0

I'm not getting proper result from this query.

SELECT Qty as op, 
       0 as secunit 
  FROM tbl_master 
 WHERE tb_sno = 1 
UNION
SELECT main_qty as op,
       main_unit as secunit 
  FROM purchase 
 WHERE tb_sno = 1 
   AND TRN_DATE < #2011/05/14# 
   AND trn_sno2 <> 0 

This show less one record from actual. is there any way to get actual result

3
  • 2
    Have you tried using UNION ALL? Perhaps there is a duplicate record in one of those recordsets. Commented May 14, 2011 at 6:16
  • @fortheworld you should probably make that an answer Commented May 14, 2011 at 6:30
  • @fortheworld: With only two columns like this there doesn't seem to be much sense in keeping the duplicates in the result set. Commented May 15, 2011 at 9:22

2 Answers 2

1

Have you tried using UNION ALL? Perhaps there is a duplicate record in one of those recordsets. (making my comment an answer)

Sign up to request clarification or add additional context in comments.

Comments

0

It looks like both of your queries set the exact same criteria on the tb_sno field (WHERE tb_sno = 1). Because of that, if op and sec_unit have the same resulting values in each query, a UNION will eliminate one of the duplicate rows. A UNION ALL will keep all duplicates, as fortheworld mentioned.

Comments

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.