MAX and Duplicate

S

Sharon

How do I get rid of duplicates after selecting MAX. Exp:
There are three exception rates for a record. Two of
these rates are duplicate and max. 7% and 7% and 5%. I
only want one 7% record to appear.

WHERE (((tblExcptRate.ExcptRate)=(SELECT Max([ExcptRate])
FROM tblExcptRate AS X Where X.[account] = [tblExcptRate].
[Account])));
 
A

Allen Browne

Where 2 values are tied, give Access some way to determine which one to
return. For example, sort on the primary key value of the subquery:
ORDER BY tblExcptRate.ID
 
G

Guest

Please expand. . .

First, I determine which ExceptRate is the highest. Then,
I need to get rid of any duplicate ExceptRates for an
account. I don't care which one. The key for
tblExcptRate is an account number

Acct# ExceptRate
11123 7%
11123 7%
11123 10%

RESULTS: 1 record for Acct# 11123 ExceptRate = 7%


-----Original Message-----
Where 2 values are tied, give Access some way to determine which one to
return. For example, sort on the primary key value of the subquery:
ORDER BY tblExcptRate.ID

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

How do I get rid of duplicates after selecting MAX. Exp:
There are three exception rates for a record. Two of
these rates are duplicate and max. 7% and 7% and 5%. I
only want one 7% record to appear.

WHERE (((tblExcptRate.ExcptRate)=(SELECT Max ([ExcptRate])
FROM tblExcptRate AS X Where X.[account] = [tblExcptRate].
[Account])));


.
 
A

Allen Browne

Okay: where is the duplicate coming from?
Is it a problem from the subquery (my previous assumption)?
Or is the duplicate coming from the main query?

If the main query, open your query in design view.
Open the Properties box.
Set the Unique Values property to Yes.

Alternatively, add the DISTINCT predicate to the SQL statement.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Please expand. . .

First, I determine which ExceptRate is the highest. Then,
I need to get rid of any duplicate ExceptRates for an
account. I don't care which one. The key for
tblExcptRate is an account number

Acct# ExceptRate
11123 7%
11123 7%
11123 10%

RESULTS: 1 record for Acct# 11123 ExceptRate = 7%


-----Original Message-----
Where 2 values are tied, give Access some way to determine which one to
return. For example, sort on the primary key value of the subquery:
ORDER BY tblExcptRate.ID

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

How do I get rid of duplicates after selecting MAX. Exp:
There are three exception rates for a record. Two of
these rates are duplicate and max. 7% and 7% and 5%. I
only want one 7% record to appear.

WHERE (((tblExcptRate.ExcptRate)=(SELECT Max ([ExcptRate])
FROM tblExcptRate AS X Where X.[account] = [tblExcptRate].
[Account])));
 
S

Sharon

Yes, DISTINCT is what I want. The duplicate is coming
from the table - which is a combination of many tables.
Now, How do I combine both the MAX and DISTINCT funtions
to my code? Please be specific as I am new to VB.

SELECT tblExcptRate.account, tblExcptRate.smple_sz,
tblExcptRate.ExcptRate INTO tblExcptRateMax
FROM tblExcptRate
WHERE (((tblExcptRate.ExcptRate)=(SELECT Max([ExcptRate])
FROM tblExcptRate AS X Where X.[account] = [tblExcptRate].
[Account])));

-----Original Message-----
Okay: where is the duplicate coming from?
Is it a problem from the subquery (my previous assumption)?
Or is the duplicate coming from the main query?

If the main query, open your query in design view.
Open the Properties box.
Set the Unique Values property to Yes.

Alternatively, add the DISTINCT predicate to the SQL statement.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Please expand. . .

First, I determine which ExceptRate is the highest. Then,
I need to get rid of any duplicate ExceptRates for an
account. I don't care which one. The key for
tblExcptRate is an account number

Acct# ExceptRate
11123 7%
11123 7%
11123 10%

RESULTS: 1 record for Acct# 11123 ExceptRate = 7%


-----Original Message-----
Where 2 values are tied, give Access some way to determine which one to
return. For example, sort on the primary key value of
the
subquery:
ORDER BY tblExcptRate.ID

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

How do I get rid of duplicates after selecting MAX. Exp:
There are three exception rates for a record. Two of
these rates are duplicate and max. 7% and 7% and 5%. I
only want one 7% record to appear.

WHERE (((tblExcptRate.ExcptRate)=(SELECT Max ([ExcptRate])
FROM tblExcptRate AS X Where X.[account] = [tblExcptRate].
[Account])));


.
 
A

Allen Browne

"DISTINCT" goes right after SELECT, before the field list:

SELECT DISTINCT tblExcptRate.account, ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top