Unknown table 'a' in MULTI DELETE的解决办法
2013-12-25 16:31
381 查看
在存储过程中,调用:
出现题目中的错误,原因如下:
在mysql中多表联合删除时,表别名只能在sql中表关联部分声明。我们应该避免不是表关联部分声明别名,因为这产生歧义的sql,从而产生不是期望的结果,例如在错误的表中删除行,举个例子来说:
对于多个表的删除,表的列表中提到的表别名的引用,使用默认数据库,除非已经明确地指定了一个数据库。例如,如果默认数据库是db1,下面的语句将不会工作,因为不确定的别名a2被认为已经有了db1:
除了默认数据库外,为了正确地匹配表的别名,我们必须明确地指定正确的数据库的名字,
根据上述理论,我的sql应该这样写:
还有需要注意的是:
1.如果你为一个表声明了别名,当你指向这个表的时候,就必须使用这个别名,例如:
2.在多个表联合删除时,不能使用order by 或limit,而单个表的删除时就没有这个限制。
3.当前,我们还不能在删除表的时候,在子查询中select from相同的表。
from:/article/6393813.html
delete a from db1.tb1 a, db2.tb2 b where a.col1 = b.col1 and a.col2 = b.col2;
出现题目中的错误,原因如下:
在mysql中多表联合删除时,表别名只能在sql中表关联部分声明。我们应该避免不是表关联部分声明别名,因为这产生歧义的sql,从而产生不是期望的结果,例如在错误的表中删除行,举个例子来说:
DELETE t1 AS a2 FROM t1 AS a1 INNER JOIN t2 AS a2;
对于多个表的删除,表的列表中提到的表别名的引用,使用默认数据库,除非已经明确地指定了一个数据库。例如,如果默认数据库是db1,下面的语句将不会工作,因为不确定的别名a2被认为已经有了db1:
DELETE a1, a2 FROM db1.t1 AS a1 INNER JOIN db2.t2 AS a2 WHERE a1.id=a2.id;
除了默认数据库外,为了正确地匹配表的别名,我们必须明确地指定正确的数据库的名字,
DELETE a1, db2.a2 FROM db1.t1 AS a1 INNER JOIN db2.t2 AS a2 WHERE a1.id=a2.id;
根据上述理论,我的sql应该这样写:
delete db1.a from db1.tb1 a, db2.tb2 b where a.col1 = b.col1 and a.col2 = b.col2;
还有需要注意的是:
1.如果你为一个表声明了别名,当你指向这个表的时候,就必须使用这个别名,例如:
-- 正确的写法: DELETE t1 FROM test AS t1, test2 WHERE ... -- 错误的写法: DELETE test FROM test AS t1, test2 WHERE ...
2.在多个表联合删除时,不能使用order by 或limit,而单个表的删除时就没有这个限制。
3.当前,我们还不能在删除表的时候,在子查询中select from相同的表。
from:/article/6393813.html
相关文章推荐
- dede(织梦)从5.5升级到5.6出现的“Unknown column 'weight' in 'field list'”的问题的解决办法
- java.sql.SQLException: Unknown type '246 in column 0 of 1 in binary-encoded result set的解决办法
- (MYSQL) Unknown table 'a' in MULTI DELETE的解决办法
- java.sql.SQLException: Unknown type '246 in column 0 of 1 in binary-encoded result set的解决办法
- Unknown column 'conuintoken' in 'field list' 解决办法
- "The string '__checksum' was not found in the string table"解决办法
- nknown table 'a' in MULTI DELETE的解决办法
- 报错 No resource identifier found for attribute '****' in package '***.***'解决办法
- 'Could not load NIB in bundle: 'NSBundle解决办法
- V4L2应用编程之huffman table don't exist,empty input file问题解决办法
- jqGrid不支持IE8的解决办法(Grid can not be used in this ('quirks') mode)
- 【Android】 Eclipse : ERROR: Unknown option '--no-crunch'的解决办法
- Mysql Table './tablename' is marked as crashed and last (automatic?) repair failed 错误解决办法
- Unknown table 'a' in MULTI DELETE的解决办法
- error: impossible constraint in `asm' 解决办法
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xb2 in position 0: ordinal not in range的解决办法
- PHP Deprecated: Comments starting with '#' are deprecated in *.ini 警告解决办法
- Unknown table 'system_sequences' in information_schema
- Error in '/' Application. 错误解决办法
- Unknown media type in type 'all/all' 问题解决方案