Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query to remove entries from table1 that exist in table 2

Status
Not open for further replies.

newtosql

Programmer
Joined
Apr 7, 2003
Messages
18
Location
US
Im new to sql server.

I have two tables, I need to write a query that will take the values out of one table if they exist in another table.
Each table has one column only and they are varchar(250). Each table has approx 20,000 rows.

I need to remove entries from table1 that already exist in table2.

Example as follows:

Table1 Table2
------ ------
car car
bus train
train blue
red bike
blue ....
green
bike
....

Thanks guys :-)

 
A temporary index on both tables on the joining field would help the access prior to deletion, but you can do the actual query many ways but the simplest is probably:
Code:
DELETE T1
FROM Table1 t1
INNER JOIN table2 t2 on t1.matchfield = t2.matchfield


"I'm living so far beyond my income that we may almost be said to be living apart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top