Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / May 2008

Tip: Looking for answers? Try searching our database.

Subqueries and Outer Joins

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kirk P. - 23 May 2008 18:23 GMT
I've got this SQL giving me a "Syntax error in Join Operation."

SELECT po.merchant_order_id AS order_id, po.source_currency_code AS curr,
po.pymt AS po_pymt, pt.pymt AS pt_pymt
FROM
(SELECT MERCHANT_ORDER_ID, SOURCE_CURRENCY_CODE,
Sum([ORDER_TOTAL]+[COUNTRY_TAX_TOTAL]) AS PYMT FROM tblRC_PAYMENT_ORDERS
GROUP BY MERCHANT_ORDER_ID, SOURCE_CURRENCY_CODE)  AS po,
(SELECT ORDER_ID, TRANSACTION_CURRENCY, Sum(PAYMENT) AS PYMT FROM
tblRCN_PAYMENT_TRANSACTION GROUP BY ORDER_ID, TRANSACTION_CURRENCY)  AS pt
RIGHT JOIN pt ON po.MERCHANT_ORDER_ID = pt.ORDER_ID;

I can't figure out where the syntax error is - how do I get this query to
work?
John Spencer - 23 May 2008 20:56 GMT
First, no square brackets allowed in a subquery in a FROM clause.

Second the JOIN should be between the two subqueries and the ON clause
after the two subqueries.

SELECT po.merchant_order_id AS order_id
, po.source_currency_code AS curr
, po.pymt AS po_pymt
, pt.pymt AS pt_pymt
FROM

(SELECT MERCHANT_ORDER_ID
, SOURCE_CURRENCY_CODE,
Sum(ORDER_TOTAL+COUNTRY_TAX_TOTAL) AS PYMT
FROM tblRC_PAYMENT_ORDERS
GROUP BY MERCHANT_ORDER_ID, SOURCE_CURRENCY_CODE)  AS po

RIGHT JOIN

 (SELECT ORDER_ID, TRANSACTION_CURRENCY, Sum(PAYMENT) AS PYMT
FROM tblRCN_PAYMENT_TRANSACTION GROUP BY ORDER_ID
, TRANSACTION_CURRENCY)  AS pt

ON po.MERCHANT_ORDER_ID = pt.ORDER_ID;

John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County

> I've got this SQL giving me a "Syntax error in Join Operation."
>
[quoted text clipped - 10 lines]
> I can't figure out where the syntax error is - how do I get this query to
> work?
Kirk P. - 23 May 2008 21:12 GMT
Perfect - thank you John!

> First, no square brackets allowed in a subquery in a FROM clause.
>
[quoted text clipped - 40 lines]
> > I can't figure out where the syntax error is - how do I get this query to
> > work?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.