티스토리 뷰

mysql

[mysql] delete / left join

명품_체인지업 2021. 3. 26. 15:10
DELETE g5_shop_cart
FROM g5_shop_cart LEFT JOIN g5_shop_order ON g5_shop_cart.od_id=g5_shop_order.od_id 
WHERE g5_shop_cart.od_id<>'' AND SUBSTR(g5_shop_order.od_time,1,10)<='2020-12-31'
DELETE A
FROM 회계분개표 AS A LEFT JOIN 회계제목관리 AS B ON A.연결ID=B.ID
WHERE A.구분='분개' AND A.연결ID<>0 AND B.날짜 IS NULL

참조 : extbrain.tistory.com/74

 

[MySQL] DELETE LEFT JOIN

▶MySQL DELETE LEFT JOIN ▶설명 하나의 쿼리로 다수의 테이블에 있는 데이터를 삭제할 수 있는 방법이 있습니다. DELETE와 LEFT JOIN을 사용하는 방법 입니다. [참고] ▶사용법 테이블1에 데이터만 삭제 DE

extbrain.tistory.com

 

 

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

 

MySQL DELETE JOIN: Deleting Data from Multiple Tables

This tutorial shows you how to delete data from multiple tables by using MySQL DELETE JOIN statement with INNER JOIN and LEFT JOIN.

www.mysqltutorial.org

MySQL DELETE JOIN with LEFT JOIN

We often use the LEFT JOIN clause in the SELECT statement to find rows in the left table that have or don’t have matching rows in the right table.

We can also use the LEFT JOIN clause in the DELETE statement to delete rows in a table (left table) that does not have matching rows in another table (right table).

The following syntax illustrates how to use DELETE statement with LEFT JOIN clause to delete rows from T1 table that does not have corresponding rows in the T2 table:

1
2
3
4
5
6
DELETE T1
FROM T1
        LEFT JOIN
    T2 ON T1.key = T2.key
WHERE
    T2.key IS NULL;

Note that we only put T1 table after the DELETE keyword, not both T1 and T2 tables like we did with the INNER JOIN clause.

'mysql' 카테고리의 다른 글

[mysql]날짜  (0) 2021.05.14
[mysql] 무료 mysql 보안  (0) 2021.05.14
[mysql] update/ left join  (0) 2021.05.14
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/06   »
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
글 보관함