gpt4 book ai didi

php - 如果字段匹配则更新和删除

转载 作者:太空宇宙 更新时间:2023-11-03 11:14:44 25 4
gpt4 key购买 nike

我知道在没有任何工作可展示的情况下提出问题有点不礼貌,但是我有点难过,我需要一些帮助。

如果另一个表中的另一个字段等于 1,我需要从 mysql 表中删除一行

我有两个表 table_1table_2

table_1有两个字段 locationevents

table_2有一个名为 location 的字段与 location 相同在 table_1

我想从 table_2 中删除一行或多行如果字段 locationtable_1相同和 events = 1

类似于:

if `events` = 1 in `table_1` in 'location' `*`;
delete row(s) from `table_2`
where `location` is the same as `location` in `table_1`

最佳答案

试试这个:

delete from `table_2` 
where location in (select location from `table_1` where events=1)

编辑

DELETE t2 FROM `table_2` t2 
JOIN `table_1` t1 ON t1.location = t2.location where t1.events=1

关于php - 如果字段匹配则更新和删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5881483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com