티스토리 뷰

mysql

[mysql] update/ left join

명품_체인지업 2021. 5. 14. 14:53

http://www.mysqltutorial.org/mysql-update-join/

 

MySQL UPDATE JOIN | Cross-Table Update in MySQL

This tutorial shows you how to perform cross-table update by using MySQL UPDATE JOIN statement with INNER JOIN and LEFT JOIN.

www.mysqltutorial.org

MySQL UPDATE JOIN syntax

We often use join clauses to query rows in a table that have (in the case of INNER JOIN) or may not have (in the case of LEFT JOIN) corresponding rows in another table. In MySQL, we can use the JOIN clauses in the UPDATE statement to perform the cross-table update.

 

The UPDATE LEFT JOIN  statement basically updates a row in a table when it does not have a corresponding row in another table.

For example, you can increase the salary for a new hire by 1.5%  using the following statement:

UPDATE employees
        LEFT JOIN
    merits ON employees.performance = merits.performance 
SET 
    salary = salary + salary * 0.015
WHERE
    merits.percentage IS NULL;
UPDATE  판매관리  
SET 합계=(SELECT sum(합계) FROM 판매제품관리 WHERE 판매제품관리.판매ID = 판매관리.ID)  
WHERE 날짜='2018-07-01'

'mysql' 카테고리의 다른 글

[mysql]날짜  (0) 2021.05.14
[mysql] 무료 mysql 보안  (0) 2021.05.14
[mysql] delete / left join  (0) 2021.03.26
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함