遇到一个情况,想通过表1的id找到表2,删除表2中barcode关联的库存数据,然后一直不能失败,如下: delete from 库存表 where BARCODE in( select BARCODE from 表1 where fmoveid= (select id from 表2 where PCID='SMX2014082604494930') ); 解决方式,加别名 delete from 库存表 where BARCODE in( select aa.BARCODE from(
update或delete语句里含有子查询时,子查询里的表不能在update或是delete语句中,如含有运行时会报错:但select语句里含有子查询时,子查询里的表可以在select语句中. 如:把总成绩小于100的学生名称修改为天才 select stu_id from score group by stu_id having sum(grade)<100; #查询总成绩小于100的学生IDupdate students set name='天才' where id in (select s
当使用mysql条件更新时--最先让人想到的写法 UPDATE buyer SET is_seller=1 WHERE uid IN (SELECT uid FROM seller) 此语句是错误的,会报错 You can't specify target table 'xxx' for update in FROM 这是因为: mysql的update的一些特点 1.update 时,更新的表不能在set和where中用于子查询: 2.update 时,可以对多个表进行更新(sqlserver
前段时间,做自动化适配的时候,查找需要的数据的时候,使用到了dblink,跨数据库实例进行访问,整段sql拼接再加上dblink,在plsql查询的时候,性能还不是很长时间,最多2分钟可以查到,前期调试阶段,在plsql里面调,没有留意到这个性能问题,后期,投入自动化使用的时候,就出现问题了,一个脚本,查找需要数据的方法,耗时长达10分钟. 原始版本设计: 查找需要数据的原有sql进行拼接筛选 如: select * from student t ,class b where t.student
在update 中的 where 子句中使用子查询: UPDATE mg_page_log as a SET page_num=1 WHERE id in( SELECT id from mg_page_log WHERE id < 100 GROUP BY visit_id) 会报: You can't specify target table 'a' for update in FROM clause 错误 所以正确的是: UPDATE mg_page_log as a ,( SELE
在使用My Sql数据库语法操作update时,第一时间想到的是一下写法: UPDATE purchase_request_detail SET convert_to_voucher_id=, convert_to_voucher_type='inventory-voucher' WHERE detail_id IN ( and item_id=) ; 但是这个时候就会报错:You can't specify target table 'xxx' for update in FROM My Sq
删除数据(DELETE) 使用前需注意:删除(DELETE),是删除一(条)行数据.假如我们有四条(行)数据,换句话说,你要删除其中一条(行) 名字为“xx”的用户,那么关于他的 i所有数据都会被删除. 并且删除和修改都有一个共同点,需要 ' WHERE ' 过滤条件,否则,也会删除多条数据,所以使用的时候一定要检查. 基本语句:DELETE FROM stu WHERE rname = "张宇"详解:DELETE(delete) 删除语句;FROM(from) 指定表;stu 表名
[1]需求: 谁的工资比Abel 高?方式一: 第一步线查出Abel共子 第二部进行过滤 SELECT salary FROM employees WHERE last_name = 'Abel'; SELECT first_name,last_name,salary FROM employees WHERE salary>11000 方式二: 自连接 SELECT e2.last_name,e2.salary FROM employees e1 JOIN employees e2 ON e
UPDATE tab_game_version as a INNER JOIN tab_game_version as b ON a.id=b.idSET a.advert_data=0 where a.advert_data is NULL UPDATE table1 AS a LEFT JOIN (SELECT CONCAT(p.f_area_name,s.f_area_name,t.f_area_name) addressPrefix,t.f_area_id FROM table2 t