I’m trying to figure out joining two querys into one. Or if I should or need to.
I have this…
SELECT
cd.SalesRep_ID AS CustomersSalesRep_ID
FROM `CustomerDetails` cd
WHERE cd.Customer_ID = $Customer_ID
That works fine and gives me the ‘SalesRep_ID’ that I’m looking for.
But I need that ‘SalesRep_ID’ for the next query like this…
SELECT
cd.IsSalesRep, cd.RepCom, cd.SalesRep_ID, sr.RepDispName, sr.DefaultRepCom
FROM `CustomerDetails` cd
LEFT JOIN `SalesReps` sr
ON cd.SalesRep_ID = sr.SalesRep_ID
WHERE cd.Customer_ID = $Customer_ID
AND sr.SalesRep_ID = $CustomersSalesRep_ID
Using both of these produces the results I’m looking for. However can they be joined together, or do they do to be?
If I’ve understood correctly, this is what you’re after: