Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I return distinct fields from one tbl that are left joined to fields from another table and a query?

Posted on 2011-03-16
2
Medium Priority
?
386 Views
Last Modified: 2012-05-11
I have a table of Consultants each with a ConsultantID and a table of Contracts each with a ContractID and a ConsultantID. Each ContractID has a MaxDailyRate

I want to see every a MaxDailyRate for each Consultant, but when I query using the SQL below to get distinct ConsultantIDs to join to the MaxDailyRate, I all the ContractIDs and duplicate ConsultantIDs

SELECT DISTINCT tblConsultants.ConsultantID, tblContracts.ConsultantID,
FROM tbl Consultants LEFT JOIN tbl Contracts On tblConsultants.ConsultantID = tblContracts.ConsultantID;

Any ideas?
0
Comment
Question by:melodymurray
2 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 35147153
I think you may have top re-state what you really want, because what you say you want doesn't require two tables.

"I want to see every a MaxDailyRate for each Consultant"

Select distinct Consultantid, maxdailyrate from contracts order by consultantid
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 35147214
try this

select C.ConsultantID, Con.MaxRate
from tblConsultants as C Inner join
(select max(MaxDailyRate) as MaxRate,ConsultantID from tblContracts as TC
 group by ConsultantID)
as Con
On C.ConsultantID=Con.ConsultantID
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question