I have this SQL Server statement, and I am not sure why it is returning no records:
SELECT
contacts.firstname ,
contacts.lastname ,
contacts.address1 ,
contacts.city,
contacts.zip,
countries.title AS countrytitle,
states.title AS statetitle
FROM providers, payableinvoices, contacts
LEFT JOIN countries ON countries.countryid=contacts.countryid
LEFT JOIN states ON states.stateid=contacts.stateid
WHERE payableinvoices.payableinvoiceid=4
AND providers.providerid=payableinvoices.providerid
AND providers.contactid=contacts.contactid"
Simply, I have the following tables:
- contacts table: its columns include contactid, firstname, lastname, address1, city, zip
- providers table: its columns include providerid, contactid
- payableinvoices table: its columns include payableinvoiceid, providerid
So it is simply linking the primary keys and foreign keys together to get the require fields that correspond to that "payableinvoiceid", which has a provider assigned to it.
Please help. Thanks!