0

I have two tables t1 and t2. Their columns only share itemid (Unique) together (They both have that column to identify items). t1 deletes rows with certain values (column called nbr). I want t2 to delete all rows with same itemid.

I've done a few attemps but no success. Here's an example of what I've tried in PHP.

$result = "DELETE FROM t1,t2 WHERE t1.value<5 AND t1.itemid=t2.itemid";
mysqli_query($db, $result) or die('Error');

I've also looked in to 'left join' but no success. So I'm starting to think that there is no simple query to do this but I want to check with this community first before trying a longer (slower) solution.

EDIT: What I want to do resembles comparing two tables with each other and removing those itemid that don't exist on both tables.

  • Probably relevant: https://stackoverflow.com/questions/1233451/delete-from-two-tables-in-one-query – aug Feb 03 '18 at 21:30

1 Answers1

-1

How about something like this:

DELETE t1
FROM t1
INNER JOIN t2 ON t1.itemid = t2.itemid
WHERE t1.value < 5

I forgot about the second table so you probably need this:

DELETE t1, t2
FROM t1
INNER JOIN t2 ON t1.itemid = t2.itemid
WHERE t1.value < 5
Marker
  • 972
  • 6
  • 9