I am having trouble with a query that I just can't figure out how to fix. Been working on this problem for two days and I need someone brilliant to help me fix it.
I have 4 tables:(only pertinent fields listed) tblContacts: ContactID tblLogins: CustID, ContactID tblSalesPerson_Customer: spCustID, custCustID tblCrushOrder: customerID
relationships are as follows: tblCrushOrder.customerID = tblSalesPerson_Customer.custCustID tblSalesPerson_Customer.custCustID = tblLogins.CustID tblLogins.ContactID = tblContacts.ContactID
Here is the current query: SELECT tblCrushOrder.ID, TBLCONTACTS.FName, TBLCONTACTS.LName, TBLCONTACTS.COMPANY, tblCrushOrder.orderDate, tblCrushOrder.orderStatus, tblCrushOrder.OrderInvoicing, tblCrushOrder.SalesPersonNumber, tblCrushOrder.CPPO FROM (tblCrushOrder INNER JOIN tblSalesPerson_Customer ON tblCrushOrder.customerID = tblSalesPerson_Customer.custCustID) INNER JOIN (TBLCONTACTS INNER JOIN tblLogins ON TBLCONTACTS.ContactID = tblLogins.ContactID) ON tblSalesPerson_Customer.custCustID = tblLogins.CustID WHERE tblSalesPerson_Customer.spCustID=15627 AND fname LIKE '%horn%' OR LName LIKE '%horn%' ORDER BY tblCrushOrder.ID DESC
The problem I am having is it is not filtering for the salespersonID (tblSalesPerson_Customer.spCustID=15627). The result is the same no matter what number I put in there or if it is there or not. How can I get it to show only the records that include the salespersonID (tblSalesPerson_Customer.spCustID)?