Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am having to interface with a framework which I query for a recordset templates, to access the database for the ADO records. No issues here. Issue : I need to JOIN 2 tables to query the 2nd tables field. Right now I query the 1st recordset to get my initially filtered records, then loop through the 2nd table with the filtered id's to see if my 2nd constraint passes. Is this even possible?
Posted

1 solution

I am unsure if something like this helps?

the following code looks for the distinct manager id's then marries them up with the distinct account id's that are found in the ValidAccounts table, then joins the accToCompany field as this is a FK:

SQL
SELECT  DISTINCT Customer.ManagerId, Company.AccountId, Count(1) as "Dist Count"
FROM ValidAccounts
INNER JOIN accToCompany ON ValidAccounts.Id = acctoCompany.accId
INNER JOIN Customer ON accToCompany.ManagerId = Customer.ManagerId
GROUP BY Customer.ManagerId, acctoCompany.accId ORDER BY Count(1) DESC


This gives me something like:

ManagerId | AccId | DistCount
     FoxB   4017     57


Not sure if this is along the lines of what you are looking for but it what it does is query multiple tables with a goal in mind in this case finding distinct values and matching the manager and account ids.

Psymon25
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900