If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Union query with left join
Hello all and please excuse me for the long post.
I have the following tables in my databases: [Daily Test Statistics TP],[Daily Test Statistics IV],[Daily Test Statistics W/S], [fail result],[pass result] with a common field name [Part No] I want to have a query which will gives me the number of [Part No] which are [NG Batch] and [OK Batch] for a given period. e.g: [Part No] [NG Batch] [OK Batch] ABC 2 6 XYZ 1 13 This query works: SELECT [Daily Test Statistics TP].[Part No], [fail result].[NG Batch], [pass result].[OK Batch] FROM ([Daily Test Statistics TP] LEFT JOIN [pass result] ON [Daily Test Statistics TP].[Part No]=[pass result].[Part No]) LEFT JOIN [fail result] ON [Daily Test Statistics TP].[Part No]=[fail result].[Part No] WHERE ((([Daily Test Statistics TP].[Test Date]) Between DateAdd("d",-3- WeekDay(Date()),Date()) And DateAdd("d",Weekday(Date()),Date()))) GROUP BY [Daily Test Statistics TP].[Part No], [fail result].[NG Batch], [pass result].[OK Batch]; I don't know how to make the union works for the following please help: SELECT [Daily Test Statistics TP].[Part No], Count(*) AS [NG Batch] FROM [Daily Test Statistics TP] WHERE ((([Daily Test Statistics TP].[Result])="fail")) GROUP BY [Daily Test Statistics TP].[Part No] union SELECT [Daily Test Statistics IV].[Part No], Count(*) AS [NG Batch] FROM [Daily Test Statistics IV] WHERE ((([Daily Test Statistics IV].[Result])="fail")) GROUP BY [Daily Test Statistics IV].[Part No] UNION SELECT [Daily Test Statistics W/S].[Part No], Count(*) AS [NG Batch] FROM [Daily Test Statistics W/S] WHERE ((([Daily Test Statistics W/S].[Result])="fail")) GROUP BY [Daily Test Statistics W/S].[Part No]; SELECT [Daily Test Statistics TP].[Part No], Count(*) AS [OK Batch] FROM [Daily Test Statistics TP] WHERE ((([Daily Test Statistics TP].[Result])="Pass")) GROUP BY [Daily Test Statistics TP].[Part No] union SELECT [Daily Test Statistics IV].[Part No], Count(*) AS [OK Batch] FROM [Daily Test Statistics IV] WHERE ((([Daily Test Statistics IV].[Result])="Pass")) GROUP BY [Daily Test Statistics IV].[Part No] UNION SELECT [Daily Test Statistics W/S].[Part No], Count(*) AS [OK Batch] FROM [Daily Test Statistics W/S] WHERE ((([Daily Test Statistics W/S].[Result])="Pass")) GROUP BY [Daily Test Statistics W/S].[Part No]; With many thanks for your time . Zaky. -- Message posted via http://www.accessmonster.com |
#2
|
|||
|
|||
Problem solved.
I created a new query containing all the [part no] from the 3 tables and then make the left join queries. -- Message posted via http://www.accessmonster.com |
#3
|
|||
|
|||
Test
|
#4
|
|||
|
|||
x with a line over it,, to dednote "mean of a sample".
Anyone kindly tell me how to do this? |
#5
|
|||
|
|||
In Access? You can't, unless you're using an RTF control.
-- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Mathsidiot" wrote in message ... x with a line over it,, to dednote "mean of a sample". Anyone kindly tell me how to do this? |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
#Error in result set with query containing table and left join to another query | bu | General Discussion | 0 | April 6th, 2005 09:48 PM |
Nested in-line Query | laura | Running & Setting Up Queries | 0 | February 11th, 2005 12:17 AM |
Union query is displaying Chinese characters for one of the fields | Seth Schwarm | Running & Setting Up Queries | 4 | January 27th, 2005 04:26 PM |
Union Query Not Returning A Value | Jeff G | Running & Setting Up Queries | 2 | October 19th, 2004 05:47 PM |
Joining 2 Left Join Queries | esi | Running & Setting Up Queries | 2 | September 16th, 2004 08:16 PM |