SQL Delete Rows Based on Another Table

mysql, sql

Solution

I think this is what you want:

DELETE FROM `table1`
WHERE `group` in (SELECT DISTINCT `group` FROM `table2`)

Problem

This is probably very easy, but it's Monday morning. I have two tables: Table1: ``` Field | Type | Null | Key | Default | Extra id | int(32) unsigned | NO | PRI | NULL | auto_increment group | int(32) | NO | | 0 | ``` Table2: ``` Field | Type | Null | Key | Default | Extra group | int(32) | NO | | 0 | ``` Ignoring other fields...I would like a single SQL DELETE statement that will delete all rows in Table1 for which there exists a Table2.group equal to Table1.group. Thus, if a row of Table1 has group=69, that row should be deleted if and only if there exists a row in Table2 with group=69. Thank you for any help.

Original source