用select语句查一下修改后的结果
select cust_id, cust_name, cust_email from Customers where cust_id = '1000000005';更新后查询:
select cust_id, cust_name, cust_contact, cust_email from Customers where cust_id = '1000000006';查询
select cust_id, cust_name, cust_contact, cust_email from Customers where cust_id = '1000000005';
我想自己试试怎么写的,然后写了下面的代码,虽然执行正确没报错,但是并没有真的改成功。
update Customers set cust_email = (select cust_email where cust_id = '1000000001') where cust_id = '1000000005';注意上面的括号中不可以写from Customers,不然报错。
select cust_email from Customers where cust_id = '1000000001'所以我还是不知道怎么在update中用子查询。。。一个失败的尝试
在update中使用from子句这个尝试也失败了
CREATE table CustCopy as select * from Customers; update CustCopy set CustCopy.cust_email = 'lalala@huhuhu.com' where CustCopy.cust_id = '1000000004'; update customers from CustCopy where Customers.cust_id = '1000000004';本意是:创建一个新表CustCopy,它和customers表一样,然后先修改一下custcopy表的一个email地址,然后再用custcopy去更新customers表。
看来是因为mysql语法的问题,暂时不想深究了
和update的注意点一样
where子句对update和delete语句是非常非常非常重要的。
关键字
updatesetdeletetruncate table