我明白,在没有任何工作要求的情况下提出问题有点粗鲁,但是我有点难过,我需要一些帮助。
如果另一个表中的另一个字段等于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`
DELETE t2
FROM `table2` t2
JOIN `table1` t1 ON t1.events = 1
AND t1.location = t2.location
试试这个:
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