[英]Delete from 'table2' where column = 'value' IF column in 'table1' = 'value'
我正在嘗試執行MySQL查詢以從'table2'中刪除行,其中'table1'='value'中的column ='value'IF列
我有2張桌子...
表1稱為“帳戶”
表2稱為“庫存物品”
有問題的“帳戶”列稱為“已禁止”
有問題的“庫存物品”列稱為“ itemid”
我想從inventoryitems
WHERE itemid
= 2340000
刪除...如果accounts
中banned
的列的值為1
額外的信息:
您可以通過第3個稱為characters
的表將表accounts
加入inventoryitems
。
表accounts
具有以下列: id
(主鍵)和banned
。
表characters
包含以下列: characterid
和accountid
( accountid
鏈接到表accounts
id
)。
表inventoryitems
有列itemid
和characterid
( characterid
鏈接characterid
表characters
)
希望這可以幫助。
DELETE FROM inventoryitems WHERE characterid IN (SELECT id from characters WHERE accountid IN (SELECT id from accounts WHERE banned = '1' ) ) AND itemid = '2340000';
以下查詢使用INNER 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;
嘗試一下,因為我從您的評論中獲悉,可以通過這種方式加入他們。
DELETE FROM inventoryitems WHERE characterid IN
(SELECT characterid from characters WHERE accountid IN
(SELECT id from accounts WHERE banned = 1))
AND itemid = '2340000';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.