Home All Groups Group Topic Archive Search About
Author
24 Jun 2006 8:13 PM
John
Hi, I would like some help with a query. I would like to delete all
rows when the key appears in one table and not the other. For example
the info in table 1 on my DB is my current work. I then import the upto
date info monthly into table 2. Currently I have to manually delete the
info from table 2, hence the need for the query to mismatch and leave
me with the current info.

Hope this makes sense

Thanks

Author
24 Jun 2006 8:48 PM
Arnie Rowland
)It's ususally a good idea to start a new thread so that your request for help doesn't get lost in someone else's responses. Also good to provide table DDL and sample data in the form of INSERT statements.)

One way to do this is:

DELETE Table2
WHERE  Table2.Key IN ( SELECT Table1.Key
                       FROM   Table1
                       WHERE {criteria in Table1}
                                          )                        

Or vice versa to delete from Table1

Let me know if this helps.

--
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."

*Yet Another Certification Exam


Show quote
"John" <john_sarah_k***@hotmail.co.uk> wrote in message news:1151180034.679815.100870@b68g2000cwa.googlegroups.com...
> Hi, I would like some help with a query. I would like to delete all
> rows when the key appears in one table and not the other. For example
> the info in table 1 on my DB is my current work. I then import the upto
> date info monthly into table 2. Currently I have to manually delete the
> info from table 2, hence the need for the query to mismatch and leave
> me with the current info.
>
> Hope this makes sense
>
> Thanks
>

AddThis Social Bookmark Button