Merge Into Use

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 ! ]


Use Precautions:

When Merge Into executed, one by one match from the results using search out and on the conditions, then decide whether to update or Insert.
So using the back of the sql can not find any data Merge Into this statement is not executed Insert and update operations.
Therefore, when the single-table operation, can only be written to take effect two sql

Reproduced in: https: //my.oschina.net/u/2552902/blog/543898

Guess you like

Origin blog.csdn.net/weixin_33724659/article/details/92326550