在mysql中删除语句,其中查询ok 0行受影响

时间:2018-01-01 13:53:31

标签: mysql sql

我在下面的语句

中遇到了mysql中的一些问题
import { FlexLayoutModule } from '@angular/flex-layout';

@NgModule({

  import:[

    FlexLayoutModule

  ])}

此声明工作正常,但以下声明无效,

   make_request (int major, int rw, struct buffer_head *bh)
    {
      struct request *req;
      int rw_ahead;


      if (rw_ahead = (rw == READA || rw == WRITEA))
        {
          if (bh->b_lock)
        return;
          if (rw == READA)
        rw = READ;
          else
        rw = WRITE;
        }
      if (rw != READ && rw != WRITE)
        panic ("Bad block dev command, must be R/W/RA/WA");

      lock_buffer (bh);

      if ((rw == WRITE && !bh->b_dirt) || (rw == READ && bh->b_uptodate))
        {
          unlock_buffer (bh);
          return;
        }
    repeat:

      if (rw == READ)
        req = request + NR_REQUEST; 
      else
        req = request + ((NR_REQUEST * 2) / 3); 
    /* find an empty request */

      while (--req >= request)
        if (req->dev < 0)
          break;

      if (req < request)
        {               
          if (rw_ahead)
        {           
          unlock_buffer (bh);
          return;
        }
          sleep_on (&wait_for_request); 
          goto repeat;
        }

      req->dev = bh->b_dev;     
      req->cmd = rw;        
      req->errors = 0;      
      req->sector = bh->b_blocknr << 1; 
      req->nr_sectors = 2;      
      req->buffer = bh->b_data; 
      req->waiting = NULL;  
      req->bh = bh;         
      req->next = NULL;     
      add_request (major + blk_dev, req);   
    }

在终端显示QUERY OK,0行受影响

2 个答案:

答案 0 :(得分:0)

您需要子查询中actorid列的表别名:

delete from actors
where not exists (select 1 from movies z where z.actorid = actors.actorid ); 

否则,actorid会解析为z.actorid

答案 1 :(得分:0)

查询select 1 from movies z where z.actorid = actorid,单独站立,为1表格的每一行都会为movies生成一个结果集。为什么? where z.actorid = actoridwhere z.actorid = z.actorid相同,后者与where 1 = 1相同,是一个接受所有行的无操作过滤器子句。

只要NOT EXISTS(that result set)中有任何行,

movies始终为false。

所以你的delete子句看起来像delete from actors where not exists (select 1)where子句总是错误的。因此delete查询在零行上运行。

你如何解决这类问题?

  1. 独立运行子查询并对结果集进行眼球处理。
  2. 将SELECT替换为UPDATE或DELETE并注视结果集。