Join 3 tables on mysql in specific situation

46 Views Asked by At

Hi I'm a newbie to this and I'm attempting to join 3 different tables:

Invoice: CustID, VIN, InvoiceType Customer: CustID, Zip Zipcode: Zip, City

I know I need to use a join clause but I'm not exactly sure how to show the specific City of the associated customer tied to the invoice along with all fields provided in invoice and show a specific InvoiceType. Here is what I currently have and I'm really where to go next or what other options to consider.

SELECT invoiceno, invoice.customerid, vin, invoicetype, city

FROM invoice, customer, zip

WHERE invoicetype = 'sell'
1

There are 1 best solutions below

0
On

try this

select
   i.CustID,
   i.VIN,
   i.InvoiceType,
   c.CustID,
   z.Zip,
   z.City      
from
   Invoice i 
inner join
   Customer c 
      on i.CustID=c.CustID 
inner join
   zip z 
      on c.zip=z.zip 
WHERE
   i.invoicetype = 'sell'