Jumat, 23 Desember 2016

Re: [MS_AccessPros] Query Returning Double Rows

 

Paco-


I'm curious why you do a RIGHT JOIN in the first query.  Are you expecting order detail rows that don't have a matching order row?  If that were to happen, you would get Null in the columns from tblOrder.

As for your second query, you will get multiple rows per part if a part appears more than once in tblOrderDetail for a given order and also appears more than once per purchase order.  Two rows in each will get you 2 * 2 or 4 rows.  You can perhaps avoid that by using SELECT DISTINCT in both queries.

John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals 
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
(Paris, France)




On Dec 22, 2016, at 10:39 PM, paco6945@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:



I have a main query and a sub query. The sub query returns the correct number of rows, but the main query doubles the number of rows. I know why this is happening, but I don't know how to fix it. The main query returns a set of the rows from the sub query for each row in the main query. Here are the queries (simplified).


Any help would be much appreciated.


Paco


******************************


SUBQUERY: qryPartsReceivedByAccount


SELECT PO, Part, Account

FROM tblOrder RIGHT JOIN tblOrderDetail ON tblOrder.OrderID = tblOrderDetail.OrderID;


MAIN QUERY


SELECT Part, DateTrans, qryPartsReceivedByAccount.Account, qryPartsReceivedByAccount.PO


FROM tblPartLog INNER JOIN qryPartsReceivedByAccount ON (tblPartLog.PONumber = qryPartsReceivedByAccount.PO) AND (tblPartLog.Part = qryPartsReceivedByAccount.Part);





__._,_.___

Posted by: John Viescas <johnv@msn.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar