473,387 Members | 1,575 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,387 software developers and data experts.

delete query frustration

Hi all,
Please help. I have a table with 2 fields of which I am trying to change
a select query into a delete query.

the select query is:

SELECT Table1.Date, Min(Table1.Ball) AS MinOfBall
FROM Table1
GROUP BY Table1.Date;

I am having trouble getting a delete query to work as I don't know how to
set the criteria.

Any help will be a god send

Mark
Nov 12 '05 #1
6 1927
What criteria do you want?

Example:
Delete * From Table1 Where Table1.Field1=23
or
Delete * From Table1 Where Table1.Field1="cats"

--
Wayne Morgan
Microsoft Access MVP
"Mark Reed" <ma*********@ntlworld.com> wrote in message
news:Ngw_b.18486$ft.17163@newsfe1-win...
Hi all,
Please help. I have a table with 2 fields of which I am trying to change a select query into a delete query.

the select query is:

SELECT Table1.Date, Min(Table1.Ball) AS MinOfBall
FROM Table1
GROUP BY Table1.Date;

I am having trouble getting a delete query to work as I don't know how to
set the criteria.

Any help will be a god send

Mark

Nov 12 '05 #2
On Mon, 23 Feb 2004 23:46:49 -0000, Mark Reed wrote:
Hi all,
Please help. I have a table with 2 fields of which I am trying to change
a select query into a delete query.

the select query is:

SELECT Table1.Date, Min(Table1.Ball) AS MinOfBall
FROM Table1
GROUP BY Table1.Date;

I am having trouble getting a delete query to work as I don't know how to
set the criteria.

Any help will be a god send

Mark


The criteria for all queries work the same. If a record contains the
matches you specify, then it will return or act upon that record.
The query builder makes it very simple to add your criteria. Take an hour
and flip thought the help file on how to use it.
--
Mike Storr
www.veraccess.com
Nov 12 '05 #3
"Mark Reed" <ma*********@ntlworld.com> wrote in message news:<Ngw_b.18486$ft.17163@newsfe1-win>...
Hi all,
Please help. I have a table with 2 fields of which I am trying to change
a select query into a delete query.

the select query is:

SELECT Table1.Date, Min(Table1.Ball) AS MinOfBall
FROM Table1
GROUP BY Table1.Date;

I am having trouble getting a delete query to work as I don't know how to
set the criteria.

Any help will be a god send

Mark


Mark,

The Group By makes your Select query non-updateable.

You might try using a subquery like:

DELETE FROM Table1 WHERE [Date] IN (SELECT Table1.[Date],
Min(Table1.Ball) AS MinOfBall FROM Table1 Group By Table1.[Date])

You might also want to avoid keywords like [Date] in your field names.

Regards,

Allen
Nov 12 '05 #4
Hi Allen,
I have tried your query but I get the following error message....."you
have written a subquery that can return more than one field without using
the exists reserved word in the main query's FROM clause. Revise the select
statement of the subquery to request only one field".

I had to change it slightly as there were no fields selected to delete.

Also, I can't find any reference within the help files to "exists".

Mark

"Allen Agee" <ag****@yahoo.com> wrote in message
news:45*************************@posting.google.co m...
"Mark Reed" <ma*********@ntlworld.com> wrote in message
news:<Ngw_b.18486$ft.17163@newsfe1-win>...
Hi all,
Please help. I have a table with 2 fields of which I am trying to change a select query into a delete query.

the select query is:

SELECT Table1.Date, Min(Table1.Ball) AS MinOfBall
FROM Table1
GROUP BY Table1.Date;

I am having trouble getting a delete query to work as I don't know how to
set the criteria.

Any help will be a god send

Mark


Mark,

The Group By makes your Select query non-updateable.

You might try using a subquery like:

DELETE FROM Table1 WHERE [Date] IN (SELECT Table1.[Date],
Min(Table1.Ball) AS MinOfBall FROM Table1 Group By Table1.[Date])

You might also want to avoid keywords like [Date] in your field names.

Regards,

Allen
Nov 12 '05 #5
"Mark Reed" <ma*********@ntlworld.com> wrote in message news:<6MG_b.662$bJ1.237@newsfe1-win>...
Hi Allen,
I have tried your query but I get the following error message....."you
have written a subquery that can return more than one field without using
the exists reserved word in the main query's FROM clause. Revise the select
statement of the subquery to request only one field".

I had to change it slightly as there were no fields selected to delete.

Also, I can't find any reference within the help files to "exists".

Mark

Mark,

That's what I get for hitting the send button before testing the
query!

It looks like your original query, SELECT Table1.[Date],
Min(Table1.Ball) AS MinOfBall FROM Table1 Group By Table1.[Date], is
trying to delete the minimum [Ball] for each Date.

To be safe, we ought to use the primary key of Table1 to prevent
deleting too many records. We can split the process into a select
query (qrySel) and our delete query (qryDel).

qrySel would look like:
SELECT First(Table1.ID) AS FirstOfID, Table1.date, Min(Table1.ball) AS
MinOfball FROM Table1 GROUP BY Table1.date;

qryDel would look like:
DELETE * FROM Table1 WHERE id in (Select FirstOfID from qrySel);

It's a good idea to make a backup before testing delete queries like
this.

Regards,
Allen
Nov 12 '05 #6
Thanks very very much Allen, works a treat
"Allen Agee" <ag****@yahoo.com> wrote in message news:45*************************@posting.google.co m...
"Mark Reed" <ma*********@ntlworld.com> wrote in message news:<6MG_b.662$bJ1.237@newsfe1-win>...
Hi Allen,
I have tried your query but I get the following error message....."you
have written a subquery that can return more than one field without using
the exists reserved word in the main query's FROM clause. Revise the select
statement of the subquery to request only one field".

I had to change it slightly as there were no fields selected to delete.

Also, I can't find any reference within the help files to "exists".

Mark

Mark,

That's what I get for hitting the send button before testing the
query!

It looks like your original query, SELECT Table1.[Date],
Min(Table1.Ball) AS MinOfBall FROM Table1 Group By Table1.[Date], is
trying to delete the minimum [Ball] for each Date.

To be safe, we ought to use the primary key of Table1 to prevent
deleting too many records. We can split the process into a select
query (qrySel) and our delete query (qryDel).

qrySel would look like:
SELECT First(Table1.ID) AS FirstOfID, Table1.date, Min(Table1.ball) AS
MinOfball FROM Table1 GROUP BY Table1.date;

qryDel would look like:
DELETE * FROM Table1 WHERE id in (Select FirstOfID from qrySel);

It's a good idea to make a backup before testing delete queries like
this.

Regards,
Allen
Nov 12 '05 #7

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

Similar topics

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...
2
by: Joe Del Medico | last post by:
I have two tables A & B and I want to delete all the records in A that are not in B. Can I do this in the query builder? It seems like a simple problem. I can easily find the records in A that...
5
by: ms | last post by:
Why does this select query return the correct records but when I make it a delete query I get a msgbox with "Could not delete from specified tables". SELECT BMIDLog.* FROM stageBMIDLog INNER...
2
by: Dave Burt | last post by:
Hi, Access officionados, I'm new here, so please cut me slack/gently tell me off if I'm out of line or in the wrong place. OK, here's something that seems silly (and is also problematic to...
13
by: forbes | last post by:
Hi, I have a user that used the Query Wizard to create a query in Access. Now she claims that her master table is missing all the data that was excluded from the query. Can you create anything...
3
by: Kevin M | last post by:
I have one table and have created a form from that table. Also, I have created a delete query. I want to but a button on the form which will delete all records from the table; however, I cannot get...
1
by: Matt | last post by:
I am writing a DELETE statement and I want to filter the records using another SELECT statement. My SELECT statement is a GROUP BY query that grabs all social security numbers from the "Data...
5
by: Bob Bridges | last post by:
Start with two tables, parent records in one and child records in the other, a one-to-many relationship. Create a select statement joining the two. Display the query in datasheet mode. When I...
0
by: =?Utf-8?B?U2hpcmxleQ==?= | last post by:
too large to be sent? I highlight, then press delete, and nothing happens! Frustrations frustration frustration!!!!!!!!! -- Shirley
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.