Hi All,
I have a table in SQL Server 2000 that contains several million member
ids. Some of these member ids are duplicated in the table, and each
record is tagged with a 1 or a 2 in [recsrc] to indicate where they
came from.
I want to remove all member ids records from the table that have a
recsrc of 1 where the same member id also exists in the table with a
recsrc of 2.
So, if the member id has a recsrc of 1, and no other record exists in
the table with the same member id and a recsrc of 2, I want it left
untouched.
So, in a theortetical dataset of member id and recsrc:
0001, 1
0002, 2
0001, 2
0003, 1
0004, 2
I am looking to only delete the first record, because it has a recsrc
of 1 and there is another record in the table with the same member id
and a recsrc of 2.
I'd very much appreciate it if someone could help me achieve this!
Much warmth,
Murray 3 3612
"M Wells" <pl**********@p lanetthoughtful .org> wrote in message
news:io******** *************** *********@4ax.c om... Hi All,
I have a table in SQL Server 2000 that contains several million member ids. Some of these member ids are duplicated in the table, and each record is tagged with a 1 or a 2 in [recsrc] to indicate where they came from.
I want to remove all member ids records from the table that have a recsrc of 1 where the same member id also exists in the table with a recsrc of 2.
So, if the member id has a recsrc of 1, and no other record exists in the table with the same member id and a recsrc of 2, I want it left untouched.
So, in a theortetical dataset of member id and recsrc:
0001, 1 0002, 2 0001, 2 0003, 1 0004, 2
I am looking to only delete the first record, because it has a recsrc of 1 and there is another record in the table with the same member id and a recsrc of 2.
I'd very much appreciate it if someone could help me achieve this!
Much warmth,
Murray
I think this is what you're looking for:
delete from dbo.MyTable
where recsrc = 1
and exists (
select * from dbo.MyTable m2
where MyTable.MemberI D = m2.MemberID
and m2.recsrc = 2)
Simon
On Fri, 02 Apr 2004 17:19:29 GMT, M Wells
<pl**********@p lanetthoughtful .org> wrote:
And just to show that I am trying, I attempted:
delete from #mw_dupetest as md where recsrc = 1 and exists (select mid
from #mw_dupetest where mid = md.mid and recsrc = 2)
This is obviously wrong, since I can't seem to assign a table alias in
a delete statement and I can't think of any other way of referring to
the mid column in the exists statement.
So, I'm hoping somone can help me understand how to do this the right
way.
Much warmth,
Murray
On Fri, 2 Apr 2004 19:28:16 +0200, "Simon Hayes" <sq*@hayes.ch > wrote: Murray
I think this is what you're looking for:
delete from dbo.MyTable where recsrc = 1 and exists ( select * from dbo.MyTable m2 where MyTable.MemberI D = m2.MemberID and m2.recsrc = 2)
Hi Simon,
Thank you for this! Seems like I was somewhat on the right track, I
just fudged on attempting to alias the table in the delete statement.
Thanks again!
Much warmth,
Murray This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Will Potter |
last post by:
I just inherited support of this app so bear with me. The scenario: Oracle
9i replicated databases, same C++ server process runs on both boxes. On a 15
minute schedule, the server that is primary deletes records out of a lock
table based on age. Once a week, the primary box is rebooted and clients are
redirected to the secondary. Once the boot is complete, the primary box
continues to handle record cleanup although clients stay pointed to...
|
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 must be UPDATED, if not, they
must be INSERTED.
Logically then, I would like to SELECT * FROM <TABLE>
WHERE ....<Values entered here>, and then IF FOUND
UPDATE <TABLE> SET .... <Values entered here> ELSE
INSERT INTO <TABLE> VALUES <Values...
|
by: Steven Stewart |
last post by:
Hi there,
I have posted about this before, but yet to arrive at a solution. I am
going to try to explain this better.
I have an Employees table and a Datarecords table (one-to-many
relationship). I have fields called InventoryOut and BalanceEnd that
are calculated on the fly for reports and when displayed on forms (they
are not part of any table). I have another field called "BalCarFor"
(Balance Carried Forward) that is part of the...
|
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
"Generations"), and it allows the user to add, edit and delete the
various records of the table.
"Generations" table has the following fields:
"IDPerson", NamePerson", "AgePerson" and "IDParent".
A record contains the information about a person (his name, his...
|
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 delete a row, only the child
record is deleted from the source tables; the parent record is still
there...which is what I wanted.
Now display fields from that query in a continuous form. When I delete a
record from that form, one of the child...
| |
by: Phil Stanton |
last post by:
Deleting a record on a membership form. Does some VB checks to see if the
family are still in the list. Warns me there is no going back if I delete
the record, so I say OK and it appears to delete OK.
Record count goes down by 1, but if I select "ShowAllRecords", there he is
back and the recordCount back to the original value
Theories gratefully received
Phil
|
by: Phil Stanton |
last post by:
Sorry to repost, but am having another look at deleting a record.
I have a form (Member) and have removed all the event procedures associated
with the Form (OnCurrent, OnDelete, OnActivate etc)
When I click on the record bar and press delete it comes up with the correct
message "You are about to delete 1 record ....", the record count drops by 1
and I say "Yes - delete it". Seems OK, record is no longer there.
Than after closing the form...
|
by: brucedodds |
last post by:
My application has a form based on a parent table with a subform based
on a child table. The relationship is Cascade Delete. The first
record displayed when the form opens has five child records. The form
allows this record to be deleted without a prompt, though SetWarnings
is set to True. When you try to delete other records, you do get a
prompt.
The problem isn't the relationship or the tables, because a test form/
subform using the...
|
by: Phil Stanton |
last post by:
I have a form based on a complex query (Lots of tables)
If I delete a record, everything appears to be OK. Get the message "Youa are
about to delete 1 record ....". I say yes. The record count goes down
correctly. Then if I do Records-->Remove Filter/Sort there are the deleted
records back as if they had never been deleted. Same thin exactly if I do
the operation on the form's recordsource query, so that eliminates anything
to do with...
|
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...
|
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,...
| |
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |