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
355 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 119

Accepted Solution

by:
Rey Obrero earned 500 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now