Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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
?
382 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

730 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