Using multiple Joins in MS Query

dragonb

New Member
Joined
Sep 15, 2014
Messages
2
Hi,

I have been trying to write a MS Query in MS Excel to retrieve data.
DataV and DQ sheets are from the same work book. The expected output is in a new work book. I have done the connectivity between two work books, importing etc. Need help on writing MSQuery to retrieve the data.
When executing the below query, I am getting "Could not add the table (SELECT"

Code:
SELECT V1.*,V2.* FROM
(SELECT DataV.C1, Sum(DataV.C3)
FROM `C:\Users\user\Desktop\Data.xlsx`.DataV DataV
GROUP BY DataV.C1) AS V1
LEFT OUTER JOIN
(SELECT DataV.C1, Sum(DataV.C3)
FROM `C:\Users\user\Desktop\Data.xlsx`.DataV DataV
WHERE (DataV.C2='Y')
GROUP BY DataV.C1) AS V2
ON V1.C1=V2.C2

Sample Input:

DataV sheet:
Col1Col2Col3
T01N1
T02N1
T03N1
T04N1
T01Y1
T04Y1
T01Y3

<tbody>
</tbody>

DQ sheet:
Col1Col2
T01A
T02B
T03F
T04K

<tbody>
</tbody>


Expected Output:

Col1Sum(Total)Sum(Col2='Y')DQ
T0154A
T021NullB
T031NullF
T0421K

<tbody>
</tbody>

Thanks in Advance
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hello

A quick glance shows a problem with the last line, ON V1.C1 = V2.C2

V2 doesn't have a C2 field

I haven't looked at anything else. If there is still a problem I will though. Please advise

regards
 
Upvote 0
Sorry that was a typo error
It should combine with C1.

Code:
SELECT V1.*,V2.* FROM (SELECT DataV.C1, Sum(DataV.C3) FROM `C:\Users\user\Desktop\Data.xlsx`.DataV DataV GROUP BY DataV.C1) AS V1 LEFT OUTER JOIN (SELECT DataV.C1, Sum(DataV.C3) FROM `C:\Users\user\Desktop\Data.xlsx`.DataV DataV WHERE (DataV.C2='Y') GROUP BY DataV.C1) AS V2 ON V1.C1=V2.C1</pre>
 
Upvote 0

Forum statistics

Threads
1,206,711
Messages
6,074,479
Members
446,071
Latest member
gaborfreeman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top