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.
Author |
Topic |
huddy1985
Starting Member
6 Posts |
Posted - 2014-07-10 : 21:54:55
|
please could someone help me with the below query. have tried joining several tables and the result displays duplicate rows of virtually every line/row. i have tried using distinct but failed miserably. thanksselect purchaseorders.traderid,suppliers.name stockbatches.partid,allpartmaster.partdesc,allpartmaster.prodgroup,goodsreceiptitems.createddate,stockbatches.warehouseid,stockbatches.locationid,stockbatches.quantity,stockbatches.status,stockbatches.batchnumber,stockbatches.batchid,stockbatches.origin,stockbatches.unitvalue,goodsreceiptitems.orderid from stockbatchesinner join allpartmaster on stockbatches.partid = allpartmaster.partnuminner join goodsreceiptbatches on stockbatches.batchnumber = goodsreceiptbatches.stockbatchidinner join goodsreceiptitems on goodsreceiptbatches.goodsreceipt = goodsreceiptitems.shipmentidinner join purchaseorders on goodsreceiptitems.orderid = purchaseorders.idinner join suppliers on purchaseorders.traderid = suppliers.idwhere allpartmaster.prodgroup = 'RMTAILS' and stockbatches.quantity >0 |
|
mmkrishna1919
Yak Posting Veteran
95 Posts |
Posted - 2014-07-11 : 02:29:25
|
The duplicate records because of one to many relationship between the tables which you have joined. Look at the columns like stockbatches.status by adding additional conditions (status= 'active')on these kind of columns you can avoid duplicate records. Anyway by adding distinct in select, you get only unique records in result set.M.MURALI kRISHNA |
|
|
huddy1985
Starting Member
6 Posts |
Posted - 2014-07-11 : 21:41:03
|
If I use alias will this help at all? Thanks |
|
|
huddy1985
Starting Member
6 Posts |
Posted - 2014-07-11 : 21:58:09
|
If I use alias will this help at all? Thanksquote: Originally posted by mmkrishna1919 The duplicate records because of one to many relationship between the tables which you have joined. Look at the columns like stockbatches.status by adding additional conditions (status= 'active')on these kind of columns you can avoid duplicate records. Anyway by adding distinct in select, you get only unique records in result set.M.MURALI kRISHNA
|
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2014-07-15 : 12:30:54
|
quote: Originally posted by huddy1985 If I use alias will this help at all? Thanks
Nope.In order for us to help, you'll have to show us your tables and provide sample data. Since we don't have access to your database we are just going to play 20+ questions. So, the best thing is for you follow the link below that describes how to post your question. That includes SQL Statements for creating the table(s) and inserting data into those tables. If you can do that and show us what you want for output, we can help guide you into a solution.http://www.sqlservercentral.com/articles/Best+Practices/61537/ |
|
|
|
|
|
|
|