USE testdb;
DROP TABLE IF EXISTS t1, t2;
CREATE TABLE t1 (
id INT PRIMARY KEY AUTO_INCREMENT
);
CREATE TABLE t2 (
id VARCHAR(20) PRIMARY KEY,
ref INT NOT NULL
);
INSERT INTO t1 VALUES (1),(2),(3);
INSERT INTO t2(ref) VALUES('A',1),('B',2),('C',3);
DELETE t1 , t2 FROM t1
INNER JOIN
t2 ON t2.ref = t1.id
WHERE
t1.id = 1;
2 row(s) affected
DELETE T1
FROM T1
LEFT JOIN
T2 ON T1.key = T2.key
WHERE
T2.key IS NULL;
DELETE customers
FROM customers
LEFT JOIN
orders ON customers.customerNumber = orders.customerNumber
WHERE
orderNumber IS NULL;
SELECT
c.customerNumber,
c.customerName,
orderNumber
FROM
customers c
LEFT JOIN
orders o ON c.customerNumber = o.customerNumber
WHERE
orderNumber IS NULL;