在 MySQL 中使用单个查询从多个表中删除 [英] Delete From MultiPle Table Using Single Query in MySQL

查看:49
本文介绍了在 MySQL 中使用单个查询从多个表中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个非常愚蠢的问题,并且可能在互联网上随处可见,但如果你们不介意,我还是希望有人在我的查询中指出问题.我正在使用单个查询从多个表中删除,两个表中没有任何外键..

I know it is a very silly question, and it may be found all over the internet, but still if you all dont mind i want someone to point out the problem in my query. I am using a single query to delete from multiple table, i dnt have any foreign keys in the two tables..

这里是两张表的表结构

表 1:dt_my_domain

table 1: dt_my_domain

|----------|----------------|
| username | domain_email   |
|----------|----------------|

表 2:dt_my_contact

table 2: dt_my_contact

|----------|-------|----------------|------------------|--------|
| user     | email | contact_person | contact_email    |  type  |
|----------|-------|----------------|------------------|--------|

现在,表 dt_my_domain 将 username 作为主键,并且 domain_email 是唯一的.

now, the table dt_my_domain have username as primary key, and domain_email is unique.

同样在表 dt_my_contact 中,电子邮件是唯一的.

similarly in table dt_my_contact email is unique.

我想从两个表中删除,基于 domain_email 和 email,这样当两者匹配时,对应的元组就会从两个表中删除

I want to delete from the two table, on the basis of domain_email and email so that when the two matches the corressponding tuple gets deleted from the two tables

这是我正在运行的查询,

Here's the query i'm running,

DELETE FROM dt_my_domain, dt_my_contact
   USING dt_my_domain
INNER JOIN dt_my_contact USING(email) 
WHERE dt_my_domain.domain_email = 'saswat.saz.routroy@gmail.com'

所以,它给出了数据库错误

so, its giving the database error

Unknown column 'email' in 'from clause'

现在我如何通过我的查询来解决这个问题,我想调试或者这个查询的问题

Now How can i solve this by my query, I want to debug or the problem with this query

推荐答案

DELETE d,c FROM dt_my_domain d inner join dt_my_contact c
   on d.domain_email = c.email
WHERE d.domain_email = 'saswat.saz.routroy@gmail.com'

这篇关于在 MySQL 中使用单个查询从多个表中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆