Delete with Join in MySQL

后端 未结 14 1004
鱼传尺愫
鱼传尺愫 2020-11-22 06:18

Here is the script to create my tables:

CREATE TABLE clients (
   client_i INT(11),
   PRIMARY KEY (client_id)
);
CREATE TABLE projects (
   project_id INT(         


        
相关标签:
14条回答
  • 2020-11-22 07:18

    I'm more used to the subquery solution to this, but I have not tried it in MySQL:

    DELETE  FROM posts
    WHERE   project_id IN (
                SELECT  project_id
                FROM    projects
                WHERE   client_id = :client_id
            );
    
    0 讨论(0)
  • 2020-11-22 07:18

    Try this,

    DELETE posts.*
    FROM posts
    INNER JOIN projects ON projects.project_id = posts.project_id
    WHERE projects.client_id = :client_id
    
    0 讨论(0)
提交回复
热议问题