Delete the correct fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This is a new one for me and I am just not getting it.

I am importing data:

[dept], [class], [Revenue] etc

I was not able to filter out a "total" line on the import so I need to build
a delete query to do it.

Pulling the records into a query and specifying "13" for [class] gives me
two records for each [dept]. I need to specify (delete) the record in each
dept where [revenue] is greatest.

Can someone help? Thank you
 
Jeff:

Try something like this:

DELETE *
FROM YourTable AS T1
WHERE Class = "13"
AND Revenue =
(SELECT MAX(Revenue)
FROM YourTable AS T2
WHERE T2.Dept = T1.Dept
AND T2.Class = "13");

Note, however, that if the Revenue value is the same in the two rows, both
would be deleted.

Ken Sheridan
Stafford, England
 
Cool . . Thanks Ken
--
Jeff C
Live Well .. Be Happy In All You Do


Ken Sheridan said:
Jeff:

Try something like this:

DELETE *
FROM YourTable AS T1
WHERE Class = "13"
AND Revenue =
(SELECT MAX(Revenue)
FROM YourTable AS T2
WHERE T2.Dept = T1.Dept
AND T2.Class = "13");

Note, however, that if the Revenue value is the same in the two rows, both
would be deleted.

Ken Sheridan
Stafford, England

Jeff C said:
This is a new one for me and I am just not getting it.

I am importing data:

[dept], [class], [Revenue] etc

I was not able to filter out a "total" line on the import so I need to build
a delete query to do it.

Pulling the records into a query and specifying "13" for [class] gives me
two records for each [dept]. I need to specify (delete) the record in each
dept where [revenue] is greatest.

Can someone help? Thank you
 

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

Back
Top