我知道在没有任何工作要求的情况下提出问题有点粗鲁,但是我有点难过,我需要一些帮助。
如果另一个表中的另一个字段等于1
,我需要从mysql表中删除一行我有两张表table_1
和table_2
table_1
有两个字段location
和events
和table_2
有一个名为location
的字段,与location
上的table_1
相同
如果字段table_2
与location
相同且table_1
= 1
events
删除一行或多行
类似的东西:
if `events` = 1 in `table_1` in 'location' `*`;
delete row(s) from `table_2`
where `location` is the same as `location` in `table_1`
答案 0 :(得分:3)
试试这个:
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
答案 1 :(得分:1)
DELETE t2
FROM `table2` t2
JOIN `table1` t1 ON t1.events = 1
AND t1.location = t2.location