Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select Query Problem () - Doubling - SQL 2008

Author  Topic 

paramu
Posting Yak Master

151 Posts

Posted - 2009-11-16 : 10:21:25
I have a select Query with multiple tables, but it's selecting double time, I can't Identify the mistake.

Anybody can hellp me ?

Thanks

Select q.sup_ref_no,q.qot_date,q.mpr_no,p.pty_name,m.mpr_date,j.proj_name,j.proj_city,q.item_code,i.itm_description,i.unit_measure,q.itm_qty,q.unit_price,q.itm_dsc_perc,q.itm_dsc_val,
q.itm_amt,q.qot_dsc_perc,q.qot_dsc_val,q.qot_amt from Purchase_Master..qotemst q,Purchase_Master..partymst p,Purchase_Master..itemmst i,Purchase_Master..mprmst m,Emp_Master..projectmst j
where q.sup_ref_no='103006' and p.pty_code=q.qot_sup_code and m.mpr_no=q.mpr_no and j.proj_code=m.proj_code and i.itm_code=q.item_code order by q.sup_ref_no


Paramu @ PARANTHAMAN

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-16 : 10:23:55
Formatted code:
SELECT   q.sup_ref_no, 
q.qot_date,
q.mpr_no,
p.pty_name,
m.mpr_date,
j.proj_name,
j.proj_city,
q.item_code,
i.itm_description,
i.unit_measure,
q.itm_qty,
q.unit_price,
q.itm_dsc_perc,
q.itm_dsc_val,
q.itm_amt,
q.qot_dsc_perc,
q.qot_dsc_val,
q.qot_amt
FROM purchase_master..qotemst q,
purchase_master..partymst p,
purchase_master..itemmst i,
purchase_master..mprmst m,
emp_master..projectmst j
WHERE q.sup_ref_no = '103006'
AND p.pty_code = q.qot_sup_code
AND m.mpr_no = q.mpr_no
AND j.proj_code = m.proj_code
AND i.itm_code = q.item_code
ORDER BY q.sup_ref_no



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-16 : 10:38:25
First you should rewrite your query by using ... inner join table on ...
And if the result gives more rows than expected then there are more than one rows in joined tables that matches the join conditions. So have a look at the data.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

paramu
Posting Yak Master

151 Posts

Posted - 2009-11-16 : 10:41:14
Thanks For The Guidences...

By
PARAMU

Paramu @ PARANTHAMAN
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-16 : 11:13:15
What are the relationships between the tables?

Are you sure you are joining on all of the key information?

Without DDL, we can't tell



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -