在tbl_usre_role里面有这么一条记录:
        select
FROM tbl_user_role ur
left join tbl_user u
on ur.user_id = u.user_id
WHERE ur.role_id = '1' 
and u.account_type != '1';
我想把这条记录删掉,这样写可以吗?
        delete
FROM tbl_user_role ur
left join tbl_user u
on ur.user_id = u.user_id
WHERE ur.role_id = '1' 
and u.account_type != '1';

解决方案 »

  1.   

    delete FROM tbl_user_role ur
    where ur.role_id = '1'
    and not exists(select * from tbl_user u where ur.user_id = u.user_id
                     and u.account_type = '1');
      

  2.   

    delete ur
    FROM tbl_user_role ur
      left join tbl_user u
        on ur.user_id = u.user_id
        WHERE ur.role_id = '1' 
        and u.account_type != '1';
    这样不行?
      

  3.   

    你这就是把原来的select换成了delete了嘛,这怎么可能行……
      

  4.   

    这样写试试。。 delete
        FROM tbl_user_role ur
        where ur.role_id='1' 
        and ur.user_id in (select user_id from tbl_user where accout_type !='1')
      

  5.   


    delete FROM tbl_user_role ur
    where exists(select 1 from 
    tbl_user u where ur.user_id = u.user_id and u.account_type != '1')
    and ur.role_id = '1'