这是我的语句:
delete from user_module where user_id in(select user_id from system_user where user_part=2)由于我的疏忽,我把system_user表里id字段写成user_id,但在mysql自动的命令行客户端里运行没有报错!执行结果:
mysql> delete from user_module where user_id in(select user_id from system_user where user_part=2);
Query OK, 0 rows affected (0.00 sec)我把语句该了一下,执行也没问题 
mysql> select * from user_module where user_id in(select user_id from system_user where user_part=2);
Empty set (0.00 sec)把前面的查询去掉,就报错了
mysql> select user_id from system_user where user_part=2;
ERROR 1054 (42S22): Unknown column 'user_id' in 'field list'让人觉的奇怪,更让我觉得不可思议的是当我运行
delete from user_module where user_id in(select user_id from system_user where user_part=2)
mysql不但不报错,而且还把我的user_module 表的内容全都删除了!
不知道这个是不是mysql的bug!我的mysql版本:5.0.51b-community-nt
Ver 14.12 Distrib 5.0.51b, for Win32 (ia32)

解决方案 »

  1.   

    MYsql不太懂,呵呵,去MYSQL问问吧!
      

  2.   

    mysql> select user_id from system_user where user_part=2; 
    提示没有这列了,被删除了??
      

  3.   

    mysql> select user_id from system_user where user_part=2; 
    ERROR 1054 (42S22): Unknown column 'user_id' in 'field list' 在字段集里没有user_id
      

  4.   

    应该不会有这种BUG啊,能否提供一下你的这两个表的 create table 语句。
      

  5.   

    This  is not a bug,please check your table.
    MayBe you can change table name,or recreate new tables to test the bug as your said,then you will find out the result.
      

  6.   

    我在5.0和5.1版本上都试了下,的确是这样的问题
    如果说"字段名=字段名变量"这个可以为“真”可以理解,但像楼主所说的这种情况的出现是不合理的,应该是个bug:select * from user_module where user_id in(select user_id from system_user where user_part=2); 
    /*若system_user where user_part=2里面没有符合条件的记录,则返回空的记录集;
    若system_user where user_part=2里面只要有1条(包括多于1条)记录符合条件,则前面的主查询“select * from user_module where ”会返回所有记录(即后面查询条件全为“真”)
    */
    所以,要解决,必须通过别名来引用:
    select * from user_module a where a.user_id in(select b.user_id from system_user b where b.user_part=2); 
    这样就会报错了
    否则,会出现前面所说的现象。
      

  7.   

    我在5.0和5.1版本上都试了下,的确是这样的问题 
    如果说"字段名=字段名变量"这个可以为“真”可以理解,但像楼主所说的这种情况的出现是不合理的,应该是个bug: select * from user_module where user_id in(select user_id from system_user where user_part=2); 
    /*若system_user where user_part=2里面没有符合条件的记录,则返回空的记录集; 
    若system_user where user_part=2里面只要有1条(包括多于1条)记录符合条件,则前面的主查询“select * from user_module where ”会返回所有记录(即后面查询条件全为“真”) 
    */ 
    所以,要解决,必须通过别名来引用: 
    select * from user_module a where a.user_id in(select b.user_id from system_user b where b.user_part=2); 这样就会报错了 
    否则,会出现前面所说的现象。
      

  8.   

    看来平时写语句时,还得多注意啊
    否则,进行delete时数据全删除了还不知道怎么回事呢
      

  9.   

    问题解决
    select * from user_module where user_id in(select user_id from system_user where user_part=2); 
    一般我们理解为
    select * from user_module a where a.user_id in(select b.user_id from system_user b where user_part=2); 
    但由于表system_user没有user_id id字段所以数据解释为
    select * from user_module a where a.user_id in(select a.user_id from system_user b where user_part=2); 
    从而造成以上的错误!
    谢谢vinsonshen的帮助!
      

  10.   

    很好,问题很严重。。确实是有问题。。我试了下。。条件字段写错了写成搜索表里的字段没有报错。。我随便写了个两张表里都没有的字段,就报错。。确实是个小bug