How to delete records in one table based on the values in another table?
use DELETE with subquery:
DELETE FROM table1 WHERE table1.cm_id IN (SELECT table2.um_id FROM table2 WHERE order_num>=518 and order_num<=520)
I prefer this way
delete from table1
using table1, table2
where table1.cm_id = table2.um_id
and table2.order_num >= 518
and table2.order_num <= 520;
DELETE table1
FROM table1 INNER JOIN table2 ON table1.cm_id = table2.um_id
AND (table2.order_num BETWEEN 518 AND 520)
--OR
DELETE
FROM table1
USING table1 INNER JOIN table2 ON table1.cm_id = table2.um_id
WHERE (table2.order_num BETWEEN 518 AND 520)
EDIT:
There was a duplicate FROM
and query has been changed as per Andriy M
comments.
delete
from table1
where cm_id IN (select um_id from table2 where order_num between 518 and 520)