码迷,mamicode.com
首页 > 其他好文 > 详细

MERGE INTO USING用法

时间:2015-08-18 15:53:51      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

MERGE INTO [your table-name] [rename your table here]     
USING ( [write your query here] )[rename your query-sql and using just like a table] ON ([conditional expression here] AND [...]...)     
WHEN MATHED THEN [here you can execute some update sql or something else ]
WHEN NOT MATHED THEN [execute something else here ! ] 

例如:

MERGE INTO table1 a USING ( select id,name from table2) b ON (a.id=b.id)     
WHEN MATHED THEN update set a.name=b.name
WHEN NOT MATHED THEN insert (id,name) values(‘id‘,‘name‘);

解析:

匹配table1 a,用b这个查询结果,用on建立联系,当匹配上用update,匹配不上用insert。

MERGE INTO USING用法

标签:

原文地址:http://www.cnblogs.com/xiufengd/p/4739247.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!