Multiple Tables In Query Using Outer Join and Equal Join

sageguy

New Member
Joined
Apr 22, 2013
Messages
1
Sorry, I know this has been covered in other threads but I'm struggling to work out how to get this to work. Naturally, I get the message about cannot have outer joins where there are more than two tables. I sort of get the principal but not the practicality of doing it in SQL.
What I have are three tables from Sage50 Accounts. The Sales Ledger, Invoice and Invoice Item tables. I need to return all the sales ledger accounts whether they have an invoice or not in a specific period (hence the parameters).
Using inner joins the SQL statement looks like this

SELECT
SALES_LEDGER.ACCOUNT_REF, SALES_LEDGER.NAME, INVOICE.INVOICE_TYPE, INVOICE.INVOICE_NUMBER, INVOICE.INVOICE_DATE, INVOICE_ITEM.STOCK_CODE, INVOICE_ITEM.QUANTITY, INVOICE_ITEM.UNIT_PRICE, INVOICE_ITEM.DISCOUNT_RATE, INVOICE_ITEM.DISCOUNT_AMOUNT, INVOICE_ITEM.NET_AMOUNT, SALES_LEDGER.ANALYSIS_1, SALES_LEDGER.ANALYSIS_2, SALES_LEDGER.ANALYSIS_3, INVOICE_ITEM.DESCRIPTION
FROM
INVOICE INVOICE, INVOICE_ITEM INVOICE_ITEM, SALES_LEDGER SALES_LEDGER
WHERE
INVOICE.INVOICE_NUMBER = INVOICE_ITEM.INVOICE_NUMBER
AND
SALES_LEDGER.ACCOUNT_REF = INVOICE.ACCOUNT_REF
AND
((INVOICE.INVOICE_DATE>=? And INVOICE.INVOICE_DATE<=?)
AND
(INVOICE.INVOICE_TYPE Not Like "Service%") AND (INVOICE_ITEM.NET_AMOUNT<>0))
ORDER BY
SALES_LEDGER.ACCOUNT_REF, INVOICE_ITEM.STOCK_CODE

For the life of me, whatever I try I cannot work out the correct change to get a left outer join between the SALES_LEDGER and INVOICE table plus an inner join between the INVOICE and INVOICE_ITEM tables. Can anyone help? I'll add you do my list of Excel deities if you can.
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,223,593
Messages
6,173,241
Members
452,505
Latest member
Neeraj1990

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