【发布时间】:2013-07-10 23:41:06
【问题描述】:
我正在尝试执行 MySQL 查询以从 'table2' where column = 'value' IF column in 'table1' = 'value' 中删除行
我有 2 张桌子...
表 1 称为“帐户”
表 2 称为“inventoryitems”
有关“帐户”的列称为“禁止”
“inventoryitems”的相关列称为“itemid”
我想从inventoryitems 删除itemid = 2340000
如果...
accounts 中的列 banned 的值为 1
额外信息:
您可以通过名为 characters 的第三个表将表 accounts 连接到 inventoryitems。
表accounts 具有列:id(主键)和banned。
表 characters 有列:characterid 和 accountid(accountid 链接到表 accounts 中的 id)。
表inventoryitems 具有列itemid 和characterid(characterid 链接到表characterid 中的characterid)
希望这会有所帮助。
【问题讨论】:
-
他们有可以加入的栏目吗?我想是的,我只需要名字。
-
他们没有可以连接的列...除非您从
accounts获取列id,然后获取characterid,其中accountid与id匹配acccounts然后在inventoryitems中找到与characterid匹配的characterid...这可能只是让您感到困惑... -
如果他们不能在一个列上加入,你怎么知道哪个项目属于哪个帐户?它们必须以某种方式相关,否则您会随机删除并希望获得最好的结果。有了这些信息,我已经删除了我的答案。我的印象是有一个共同的专栏可以加入。
-
尼克是正确的,他们需要以某种方式加入,即使通过第三张表。
-
是的,它们通过另一个名为
characters的表关联...我将尝试更清楚地解释并包含更多有助于关联它们的列...accounts表有列id和banned。表inventoryitems具有列characterid和itemid。表characters具有列accountid(连接到accounts表列id)和characterid。
标签: mysql where sql-delete