-1

I want to delete customer id where id customer in table order is doesn't exist

DELETE FROM 
    customers a 
WHERE 
    a.id_customers IN(
        SELECT 
            c.id_customers 
        FROM 
            customers c 
        WHERE 
            c.id_customers NOT IN (
                SELECT DISTINCT 
                    o.customer_id 
                FROM orders o
            )
    )

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'a WHERE a.id_customers IN(SELECT c.id_customers FROM customers c WHERE c.id_cust' at line 1

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55

2 Answers2

1

You can use NOT EXISTS as without aliasing a as in the following query

DELETE FROM customers 
 WHERE NOT EXISTS 
        ( SELECT 0
            FROM orders o 
           WHERE customers.id_customers = o.customer_id );
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
0

Can you try this:

DELETE customers a WHERE a.id_customers NOT IN (SELECT id_customers FROM orders GROUP BY id_customers) b
alimbaronia
  • 504
  • 2
  • 10