Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete from table using multiple identifying columns in another table

Tags:

sql-server

I have two tables as described:

Table 1

Column A, Column B, Column C, Column D

Table 2

Column A, Column B, Column C, Column E, Column F

There is no relationship between the tables other than the data contained within them (table 2 is a temporary table). I want to delete rows from table one where they exist in table 2. However, it must be based on the combination of three columns. For example, delete in table 1 if there is a record in table two where columns A, B and C all match.

like image 961
MogulBomb Avatar asked Apr 26 '26 03:04

MogulBomb


1 Answers

You're probably looking for an INNER JOIN DELETE.

DELETE a
FROM Table1 a
INNER JOIN Table2 b
ON a.ColumnA=b.ColumnA
AND a.ColumnB=b.ColumnB
AND a.ColumnC=b.ColumnC

(Or whatever the relationship is.)

like image 106
Jiggles32 Avatar answered Apr 27 '26 23:04

Jiggles32