<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[Mysql 高级sql操作： DELETE,UPDATE与LEFT JOIN ]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Fri, 31 Oct 2008 10:40:41 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	<div class="code">UPDATE:<br/>UPDATE A SET ApproverID=NULL,ApproveDate=NULL,ApproveResult=100,CheckerID=null,CheckDate=null, IsCheck=0<br/>FROM &#91;SH_MaterialApplyBuyBill&#93; A<br/>LEFT JOIN &#91;SH_MaterialApplyBuyBillDetail&#93; B ON A.ID=B.&#91;MaterialApplyBuyBillID&#93;<br/>WHERE A.id=125 AND @InDetailCount=0<br/>DELETE:<br/>DELETE A FROM &#91;SH_ClosingBalance&#93; A LEFT JOIN &#91;SH_StoreHouse&#93; B ON A.StoreHouseID=B.ID<br/>WHERE B.departmentID=&#039;1000&#039;</div><br/>如题：<br/>前段时间程序中修改、删除sql时，涉及处理两个表。最近了解到，mysql可以直接联表操作：<br/><br/>联表修改：<br/>update t1,t2 set t1.c1=* ,t2.c2=* where t1.c3=t2.c3 and t1.c2=*;<br/>例如：修改纸条状态<br/>update relation , information set relation.status = 2 where relation.infoid=information.infoid and information.group = 0 and relation.id in (125,126,127,128) and relation.owneruid = 1 and relation.type = 1<br/>这样就可以直接修改符合条件的两个表的字段了。<br/><br/>联表删除：<br/>delete t1,t2 from t1 left join t2 on t1.c3=t2.c3 where t1.c2=*;<br/>例如：删除通知：<br/>DELETE relation,<br/>information FROM relation LEFT JOIN information ON relation.infoid = information.infoid WHERE information.group =0 AND relation.id IN ( 19 ,20,21 ) AND relation.owneruid =1<br/> 这样就可以一下删除两个表的相关记录了。<br/><br/>另外遍历整个数据表时，有一个比select更快的方法就是handler。大致用法如下：<br/>handler 表名 open;<br/>handler 表名 read next limit n;<br/>handler 表名 close;<br/><br/>例如：遍历delinfoid表<br/>mysql&gt; handler delinfoid open;<br/>mysql&gt; handler delinfoid read next limit 10;<br/>mysql&gt; handler delinfoid read next limit 10;<br/>mysql&gt; handler delinfoid close;<br/><br/>在read时，如果不加limit的话，默认一次只读一条。<br/><br/><br/>以上是使用这些方法的一些大致介绍，具体的大家可以查看手册 or google一下。
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] Mysql 高级sql操作： DELETE,UPDATE与LEFT JOIN ]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>