473,748 Members | 2,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete Query with an Inner Join

4 New Member
Purpose:
This is a Distribution List database.

Function:
Users create many different email distribution lists, tailoring each to fit their specific needs

Wanted:
Users can combine multiple distribution lists to create new ones. Sometimes, however, they discover they've made a mistake. Users would like to delete from a new distribution list only the records that belong to an old one.

Technique (Short)
I've created a query (qry_PeopleJoinD istro) that identifies all records in the new distribution list.

I have created a second query which looks at all the records in the new Distribution list (qry_PeopleJoinD istro) and identifies only those which are also contained in an old Distribution list. This second query is called qry_Distro_Anal ytics_ByDistroL ist.

A schematic of this would look like two overlapping circles. Each circle represents a Distribution list. The intersecting region would represent those records contained in both.

My goal would be to delete overlapping records from the new distribution list ONLY. After removing these records, the schematic represented by two circles above would no longer have an intersecting region.


Technique (Long)- Let the Madness Begin!

A query selects the records in a new distribution list with the query called, "qry_PeopleJoin Distro", which is based on an open user form.

These records are narrowed, according to old distribution lists, with a second user controlled field called "[Forms]![frm_Distro_Dash Board_Super]![txtDistroList]"

The Select Query Looks Like this:

SELECT
tbl_Distro_Join _People.Distrib ution_List, tbl_Distro_Join _People.People
FROM
(tbl_People INNER JOIN qry_PeopleJoinD istro ON tbl_People.[Personal Contact Serial] = qry_PeopleJoinD istro.[Personal Contact Serial]) INNER JOIN tbl_Distro_Join _People ON tbl_People.[Personal Contact Serial] = tbl_Distro_Join _People.People
WHERE (((tbl_Distro_J oin_People.Dist ribution_List)=[Forms]![frm_Distro_Dash Board_Super]![txtDistroList]) AND ((tbl_Distro_Jo in_People.Peopl e)=[qry_PeopleJoinD istro]![Personal Contact Serial]));
Summary of My Problem:
Turn the SELECT query above into a DELETE query. Records should be removed from tbl_Distro_Join _People.
Apr 19 '08 #1
1 3297
ADezii
8,834 Recognized Expert Expert
Purpose:
This is a Distribution List database.

Function:
Users create many different email distribution lists, tailoring each to fit their specific needs

Wanted:
Users can combine multiple distribution lists to create new ones. Sometimes, however, they discover they've made a mistake. Users would like to delete from a new distribution list only the records that belong to an old one.

Technique (Short)
I've created a query (qry_PeopleJoinD istro) that identifies all records in the new distribution list.

I have created a second query which looks at all the records in the new Distribution list (qry_PeopleJoinD istro) and identifies only those which are also contained in an old Distribution list. This second query is called qry_Distro_Anal ytics_ByDistroL ist.

A schematic of this would look like two overlapping circles. Each circle represents a Distribution list. The intersecting region would represent those records contained in both.

My goal would be to delete overlapping records from the new distribution list ONLY. After removing these records, the schematic represented by two circles above would no longer have an intersecting region.


Technique (Long)- Let the Madness Begin!

A query selects the records in a new distribution list with the query called, "qry_PeopleJoin Distro", which is based on an open user form.

These records are narrowed, according to old distribution lists, with a second user controlled field called "[Forms]![frm_Distro_Dash Board_Super]![txtDistroList]"

The Select Query Looks Like this:

SELECT
tbl_Distro_Join _People.Distrib ution_List, tbl_Distro_Join _People.People
FROM
(tbl_People INNER JOIN qry_PeopleJoinD istro ON tbl_People.[Personal Contact Serial] = qry_PeopleJoinD istro.[Personal Contact Serial]) INNER JOIN tbl_Distro_Join _People ON tbl_People.[Personal Contact Serial] = tbl_Distro_Join _People.People
WHERE (((tbl_Distro_J oin_People.Dist ribution_List)=[Forms]![frm_Distro_Dash Board_Super]![txtDistroList]) AND ((tbl_Distro_Jo in_People.Peopl e)=[qry_PeopleJoinD istro]![Personal Contact Serial]));
Summary of My Problem:
Turn the SELECT query above into a DELETE query. Records should be removed from tbl_Distro_Join _People.
This looks like the perfect situation for a Sub-Query. The following Query will Delete all Records in tblDistribution List_New that have identical Records in tblDistribution List_Old based on the [DistributionID] Field. You should be able to adapt the SQL for your specific needs:
Expand|Select|Wrap|Line Numbers
  1. DELETE  FROM tblDistributionList_New
  2. WHERE EXISTS 
  3. (SELECT [DistributionID]                                       
  4. FROM tblDistributionList_Old                                     
  5. WHERE tblDistributionList_Old.[DistributionID] = tblDistributionList_New.[DistributionID]); 
Apr 20 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2177
by: Yossi Naggar | last post by:
Hello to everyone, I am an experienced user in MSSQL Server. Lately I have been started using MySQL. I managed to create my database and tables. When I wanted to execute the following query: delete from adminpages where parentid IN ( select DISTINCT A.id from adminpages AS A where A.name='galeries' );
0
434
by: Clay Luther | last post by:
Again, we have an odd performance problem with PGSQL, 7.4b2. Here is the query: delete from numplan where pkid in (select numplan.pkid from numplan left outer join pilothuntgroup on numplan.pkid=pilothuntgroup.fknumplan left outer join devicenumplanmap on numplan.pkid = devicenumplanmap.fknumplan where numplan.tkpatternusage=2 and pilothuntgroup.fknumplan is null
3
8088
by: William Case | last post by:
I cannot believe I'm having this much trouble doing such a simple thing! I have two tables with identical structure. I can use an A2K select query to show the records in table 1 that match those in table two based on an inner join between two unindexed fields. Here's the SQL code for the select query that DOES work: SELECT tblEmailLetters_TEMP.*
2
2582
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 me). I have a query which is updateable when viewed as a datasheet in Access (you can insert, delete, update). Using queries, I can insert and update, but not delete.
8
25074
by: John Baker | last post by:
Hi: Access 2000 W98! I have a table with numerous records in it, and am attempting to delete certain records that have been selected from it. These are selected based on the ID number in a different table. While I am using the tools in Access for query setup, its easier to show it on here using the SQL for the query, which is as follows( the table is ): DELETE .date, .,
1
2677
by: Simon Harris | last post by:
I'm using Access2000 and I've got a problem with a delete query which I'm *sure* I had working before )-: I have a table (logfile) which I import from an external source that has a load of stuff I don't need. So I have another table (tests_not_reqd) that lists the tests I don't need. Link 'em together with an inner join to see the tests in 'logfile' that I don't need - all looking good so far ... SELECT Logfile.* FROM tests_not_reqd INNER...
2
5067
by: NoSpam | last post by:
Hi, I am working with C# and ASP.NET with code behind and a SQL Server. I'm making an e-shop. When clients see what they have in their basket, I added a function DELETE to delete a line. It took me hours to get it working in both the dataset and the database itself. It works now, but the code looks so ugly to me. Can someone tell me what I use too much, and what could be changed? I am using a temporary table to store the basket with an...
1
3622
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 With Import Date Current" table on a given day where there was only one transaction (count of SSN = 1). I want to delete these records from the "Data With Import Date Current" table. I would like to do this by joining the "Data With Import Date...
3
1784
by: jpatchak | last post by:
The following select query gives me the set of records I want to delete: SELECT tblCaseNumbers.* FROM (tblCaseNumberDump INNER JOIN ON tblCaseNumberDump.SSN = .) INNER JOIN tblCaseNumbers ON . = tblCaseNumbers.ProspectKey WHERE ((=IIf(Right(,1)='D','D',IIf(Right(,1)='A','PLP', IIf(Right(,1)='B','SLP','M'))))); When I try to make it a delete query however: DELETE tblCaseNumbers.* FROM (tblCaseNumberDump INNER JOIN ON...
0
8996
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9562
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.