473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Delete Query maximum values

I want to make a delete query that deletes all the items that are in
the minorty. For example, in the field " Houses " there are 10 rows
with value 1 , 3 rows with value 3 and 4 rows with value 6. In this
case I must delete all values except the value 1
I suppose the code should use Dcount, Max or something like that but
I cannot do it. Any help ?"

Aug 15 '07 #1
2 2671
My**************@gmail.com wrote:
I want to make a delete query that deletes all the items that are in
the minorty. For example, in the field " Houses " there are 10 rows
with value 1 , 3 rows with value 3 and 4 rows with value 6. In this
case I must delete all values except the value 1
I suppose the code should use Dcount, Max or something like that but
I cannot do it. Any help ?"
You could create a Totals query. Drop in the type (houses field) 2
times and the Values field. Click the Totals button. Group on type in
the first column and values and then Count on type. Call it Query1

Now create a second query. Use Query1. Drag the type and values and
count fields into columns. Group on Type and values and get the Max
count. Save as Query2.

Let's say the table in question is Table1. Now write some code.
Dim rst As DAO.Recordset
Dim strSQL As String
Set rst As Currentdb.openrecordset("QUery2",dbopensnapshot)
If rst.recordcount 0 then
rst.MoveFirst
do while not rst.Eof
strSQL = "Delete Table1.* From Table1 " & _
"where type = '" & rst!Type & "' And " & _
"value <" & rst!Values
Currentdb.Execute strSQL
rst.movenext
Loop
msgbox "Done
Endif
rst.close
set rst = Nothing

Make a copy of your table before running...just to be sure. BTW, I have
no idea what your field names are so you need to change them to reflect
the names in your table and the column names in Query2.


Aug 15 '07 #2
delete * from foo
where houses <>
(
select top 1 houses
from foo
group by houses
)
My**************@gmail.com wrote:
I want to make a delete query that deletes all the items that are in
the minorty. For example, in the field " Houses " there are 10 rows
with value 1 , 3 rows with value 3 and 4 rows with value 6. In this
case I must delete all values except the value 1
I suppose the code should use Dcount, Max or something like that but
I cannot do it. Any help ?"
Aug 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chris | last post by:
Hi, sorry to post OT but i cant find the MySQL newsgroup, however i am hoping to pick up on some expert advice from php/mysql gurus here. I'm having some trouble performing a delete across two...
1
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB...
4
by: Orion | last post by:
Hi, This is kind of last minute, I have a day and a half left to figure this out. I'm working on a project using ms-sqlserver. We are creating a ticket sales system, as part of the system, I...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
2
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
1
by: jmarcrum | last post by:
Hello all! i have a “monitor-type” program, where my program recognizes my defined "commands”, and executes the given command, or produces an error message that says “unrecognized command”. After...
8
by: Michel Esber | last post by:
Hello, Env: DB2 V8 LUW FP16 running Linux create Table X (machine_id varchar(24) not null, ctime timestamp not null); create index iFoo on X (MACHINE_ID, CTIME) allow reverse scans; alter...
10
beacon
by: beacon | last post by:
Hi everybody, This is probably going to sound unorthodox, but I have to log records that are deleted...I know, go figure. Anyway, I have a form with a (continuous) subform, and on the subform I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.