MERGE into
时间: 2023-10-19 11:27:54 浏览: 109
MERGE INTO is a SQL statement that allows you to combine rows from two or more tables into a single result set based on a specified condition. It is commonly used for performing updates or inserts based on certain criteria.
For example, let's say you have two tables: "employees" and "salary_updates". You want to update the salary of employees based on the data in the "salary_updates" table. You can use the MERGE INTO statement to accomplish this:
```sql
MERGE INTO employees
USING salary_updates
ON (employees.employee_id = salary_updates.employee_id)
WHEN MATCHED THEN
UPDATE SET employees.salary = salary_updates.new_salary;
```
In this example, the MERGE INTO statement combines the "employees" table with the "salary_updates" table based on matching employee IDs. When a match is found, it updates the salary column in the "employees" table with the new salary from the "salary_updates" table.
Please note that the exact syntax and behavior of the MERGE INTO statement may vary depending on the database management system you are using.
阅读全文