Delete rows in MySQL matching two columns in another table

Ellen Spertus

I am using MySQL and would like to delete entries from table T1:

user_id  level_id  other_data
   1        5         ...
   2        7         ...
   :

where the user_id and level_id values appear together in table T2:

user_id  level_id
   1         5
   2         6

In this example, the first row would be deleted from table T1.

I tried:

delete from T1 where (user_id,level_id) in select user_id,level_id from T2;

but that has a syntax error.

Gordon Linoff

You are pretty close. Try using exists:

delete from T1
    where exists (select 1
                  from t2
                  where t1.user_id = t2.user_id and t1.level_id = t2.level_id
                 );

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Excel table lookup matching values of two columns

From Dev

MySQL: Update all rows in 2 table matching results of another query

From Dev

How to select non-matching rows from two mysql table

From Dev

MySQL delete duplicate rows in table

From Dev

Delete duplicate rows in two columns simultaneously

From Dev

MySQL select row with two matching joined rows from another table

From Dev

How to get matching data from another SQL table for two different columns: Inner Join and/or Union?

From Dev

mysql: select rows from another table as columns

From Dev

MYSQL Import Column from another table matching multiple columns

From Dev

Getting table rows in order of sum of count of two another columns from another table

From Dev

Mysql query to get rows of a table as columns of another, with column names from third table

From Dev

Fetch rows in MySQL which are not present in both columns from another table

From Dev

How to delete records in another mysql table only if all the matching records have been flagged

From Dev

Efficiently deleting rows from one table where not matching another [MySQL]

From Dev

Delete Rows based on another table with key having multiple columns

From Dev

join two table with non-matching rows

From Dev

MYSQL Query matching column names to rows in another table

From Dev

Delete all rows in a table with MySQL?

From Dev

Delete rows in MySQL matching two columns in another table

From Dev

Insert rows into a table from another two tables separately in mysql

From Dev

MYSQL Import Column from another table matching multiple columns

From Dev

MySQL query to find if a value of one column in one table is between two values in two columns on another table

From Dev

Delete rows in one table with query in another table

From Dev

MySQL: Update rows in table, from rows with matching key in another table

From Dev

MySQL combine two columns into rows

From Dev

Table rows into columns in mysql

From Dev

MYSQL: Return all rows in one table along with the sum of matching rows in another

From Dev

Fetch rows in MySQL which are not present in both columns from another table

From Dev

How to delete rows from one table matching another table?

Related Related

  1. 1

    Excel table lookup matching values of two columns

  2. 2

    MySQL: Update all rows in 2 table matching results of another query

  3. 3

    How to select non-matching rows from two mysql table

  4. 4

    MySQL delete duplicate rows in table

  5. 5

    Delete duplicate rows in two columns simultaneously

  6. 6

    MySQL select row with two matching joined rows from another table

  7. 7

    How to get matching data from another SQL table for two different columns: Inner Join and/or Union?

  8. 8

    mysql: select rows from another table as columns

  9. 9

    MYSQL Import Column from another table matching multiple columns

  10. 10

    Getting table rows in order of sum of count of two another columns from another table

  11. 11

    Mysql query to get rows of a table as columns of another, with column names from third table

  12. 12

    Fetch rows in MySQL which are not present in both columns from another table

  13. 13

    How to delete records in another mysql table only if all the matching records have been flagged

  14. 14

    Efficiently deleting rows from one table where not matching another [MySQL]

  15. 15

    Delete Rows based on another table with key having multiple columns

  16. 16

    join two table with non-matching rows

  17. 17

    MYSQL Query matching column names to rows in another table

  18. 18

    Delete all rows in a table with MySQL?

  19. 19

    Delete rows in MySQL matching two columns in another table

  20. 20

    Insert rows into a table from another two tables separately in mysql

  21. 21

    MYSQL Import Column from another table matching multiple columns

  22. 22

    MySQL query to find if a value of one column in one table is between two values in two columns on another table

  23. 23

    Delete rows in one table with query in another table

  24. 24

    MySQL: Update rows in table, from rows with matching key in another table

  25. 25

    MySQL combine two columns into rows

  26. 26

    Table rows into columns in mysql

  27. 27

    MYSQL: Return all rows in one table along with the sum of matching rows in another

  28. 28

    Fetch rows in MySQL which are not present in both columns from another table

  29. 29

    How to delete rows from one table matching another table?

HotTag

Archive