Srihari
Srihari

Reputation: 2429

MS Access Database SQL Query

I have 3 Tables called Invoice, Customer and Company. I want to merge this 3 tables into single using Query. In Invoice Table contain Customer Id and Company Id. How to Join 3 tables ?

I tried Invoice and Customer Table working fine with this query. But I dont have idea to add 3rd table with this.

SELECT RPT_Invoice_Less.InvoiceNumber, RPT_Invoice_Less.Terms,
    RPT_Invoice_Less.Invoicedate, RPT_Invoice_Less.OurQuote,
    RPT_Invoice_Less.SalesPerson, RPT_Customer.CustomerName,
    RPT_Customer.CustomerId, RPT_Customer.ContactPerson,
    RPT_Customer.BillingAddress, RPT_Customer.DeliveryAddress,
    RPT_Invoice_Less.OrderNumber, RPT_Invoice_Less.ShippingBy,
    RPT_Invoice_Less.ShipReferenceNo, RPT_Invoice_Less.Notes,
    RPT_Invoice_Less.Price, RPT_Invoice_Less.Discount,
    RPT_Invoice_Less.Shipping, RPT_Invoice_Less.Tax,
    RPT_Invoice_Less.GrandTotal, RPT_Invoice_Less.Company
FROM RPT_Invoice_Less
INNER JOIN RPT_Customer
ON RPT_Invoice_Less.CustomerId = RPT_Customer.CustomerId;

this code working fine for 2 tables

SELECT RPT_Invoice_Less.InvoiceNumber, RPT_Invoice_Less.Terms, RPT_Invoice_Less.Invoicedate, RPT_Invoice_Less.OurQuote, RPT_Invoice_Less.SalesPerson, RPT_Customer.CustomerName, RPT_Customer.CustomerId, RPT_Customer.ContactPerson, RPT_Customer.BillingAddress, RPT_Customer.DeliveryAddress, RPT_Invoice_Less.OrderNumber, RPT_Invoice_Less.ShippingBy, RPT_Invoice_Less.ShipReferenceNo, RPT_Invoice_Less.Notes, RPT_Invoice_Less.Price, RPT_Invoice_Less.Discount, RPT_Invoice_Less.Shipping, RPT_Invoice_Less.Tax, RPT_Invoice_Less.GrandTotal, RPT_OrionSystem.Company, RPT_OrionSystem.CompanyId
FROM RPT_Invoice_Less 
INNER JOIN RPT_Customer 
ON RPT_Invoice_Less.CustomerId = RPT_Customer.CustomerId
INNER JOIN RPT_OrionSystem
ON RPT_Invoice_Less.CompanyId = RPT_OrionSystem.CompanyId;

This code showing syntax error.

Help me to add 3rd Company table to this.

Upvotes: 0

Views: 73

Answers (1)

Steve
Steve

Reputation: 216293

Supposing that you have a CompanyID field (or something like that) in the RPT_Customer table or in the RPT_Invoice_Less, it is just a matter to add another INNER JOIN

....
FROM ((RPT_Invoice_Less
INNER JOIN RPT_Customer
ON RPT_Invoice_Less.CustomerId = RPT_Customer.CustomerId)
INNER JOIN RPT_OrionSystem 
ON  RPT_Invoice_Less.CompanyID = RPT_OrionSystem.CompanyID)

Upvotes: 1

Related Questions