Click here to Skip to main content
15,905,414 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,
Please find the below query and output.accatuly we are Join the Sheet1 and Sheet2 tables and the result will be displayed as shown below output if stpe is ‘rework’ in Sheet1 and step is ‘External’ in sheet2 . But how to get the result if any one step is available like sheet1.step ="Rework" or Sheet2.Step="External" in this query.
I want the result as shown below
1)
map                              sheet1.step      Sheet2.step
21-147-00021-0000_20110608       Rework

OR
2)
map                              sheet1.step      Sheet2.step
21-147-00021-0000_20110608                            External

Query
SQL
SELECT Sheet1.map, Sheet1.step, Sheet2.step 
FROM Sheet1 
INNER JOIN Sheet2 ON (Sheet1.mapType = Sheet2.mapType) AND 
                     (Sheet1.map = Sheet2.map) AND 
                     (Sheet1.batch = Sheet2.batch) AND 
                     (Sheet1.area = Sheet2.area) 
WHERE (((Sheet1.area)="Completions") AND 
       ((Sheet1.batch)="Michigan") AND 
       ((Sheet1.step)="Rework") AND 
       ((Sheet2.Step)="External")) 
GROUP BY Sheet1.map, Sheet1.step, Sheet2.step;
Output
map	                        Sheet1.step	Sheet2.step
21-147-00021-0000_20110608	Rework	        External



[edit]Indentation, code blocks. Reformatted query to be readable - OriginalGriff[/edit]
Posted
Updated 3-Aug-11 21:58pm
v5

1 solution

SELECT Sheet1.map, Sheet1.step, Sheet2.step
FROM Sheet1
INNER JOIN Sheet2 ON (Sheet1.mapType = Sheet2.mapType) AND
(Sheet1.map = Sheet2.map) AND
(Sheet1.batch = Sheet2.batch) AND
(Sheet1.area = Sheet2.area)
WHERE (((Sheet1.area)="Completions") AND
((Sheet1.batch)="Michigan") AND
((Sheet1.step)="Rework") AND
((Sheet2.Step)="External")) OR (((Sheet1.area)="Completions") AND
((Sheet1.batch)="Michigan") AND
((Sheet1.step)="Rework") OR
((Sheet2.Step)="External"))
GROUP BY Sheet1.map, Sheet1.step, Sheet2.step




Hope this will help you out
 
Share this answer
 
Comments
Member 7993229 4-Aug-11 22:00pm    
Thanks for your support. I have helpfull with your solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900