0

我正在尝试执行 MySQL 查询以从 'table2' 中删除行,其中 column = 'value' IF 列在 'table1' = 'value'

我有2张桌子...

表 1 称为“账户”
表 2 称为“库存项目”

'accounts' 的相关列称为 'banned'
'inventoryitems' 的相关列称为 'itemid'

我想 DELETE FROM inventoryitemsWHERE itemid= 2340000 IF... 中的列bannedaccounts值为1

额外的信息:

您可以通过名为 的第三张表accounts加入该表。inventoryitemscharacters

accounts有列:(id主键)和banned

characters有列:characteridaccountid(表中的accountid链接)。idaccounts

inventoryitems有列itemidcharacterid(表中的characterid链接)characteridcharacters

希望这可以帮助。

4

3 回答 3

1

DELETE FROM inventoryitems WHERE characterid IN (SELECT id from characters WHERE accountid IN (SELECT id from accounts WHERE banned = '1' ) ) AND itemid = '2340000';

于 2013-07-11T20:07:53.800 回答
0

以下查询使用 aINNER JOIN从表中删除一行inventoryitems

DELETE i FROM inventoryitems i  
INNER JOIN characters c ON i.characterid = c.characterid 
INNER JOIN accounts a ON c.accountid = a.id 
WHERE i.itemid = 2340000 && a.banned = 1;
于 2013-07-10T23:55:04.230 回答
0

试试这个,因为我从你的评论中收集到他们可能会以这种方式加入。

DELETE FROM inventoryitems WHERE characterid IN
(SELECT characterid from characters WHERE accountid IN
(SELECT id from accounts WHERE banned = 1))
AND itemid = '2340000';
于 2013-07-10T23:59:12.117 回答