我在创建语句以删除多个字段上的连接时遇到问题。我搜索过并找到了许多解决方案,但这些解决方案仍然无效。
我有两张桌子: orders.profile和orders.qualified
没有一个简单的单个字段可以加入,但是多个。基本上根据客户需求,存储在其个人资料中的某些项目可能不符合地理位置,因此需要将其删除。
这是我一直在玩的东西,目前我正在收到UNKNOWN TABLE错误,当我从开头的表定义中删除数据库时,我收到NO DATABASE SELECTED错误。
DELETE FROM orders.profile
USING orders.profile AS p
LEFT OUTER JOIN orders.qualified AS q
ON p.cust_id = q.cust_id
AND p.job_number = q.job_number
AND p.job_seg = q.job_seg
AND p.zip = q.zip
AND p.carrier_route = q.carrier_route
WHERE p.cust_id = {the cust_id in question}
AND p.job_number = {the job number in question}
and q.qualified = 0;
答案 0 :(得分:1)
在没有USING
声明的情况下尝试删除:
DELETE p FROM
orders.profile AS p
LEFT OUTER JOIN orders.qualified AS q
ON p.cust_id = q.cust_id ...
如果这不起作用,就会发生更为根本的事情。
答案 1 :(得分:1)
根据Holger Brandt的回答,我能够通过定义数据库和别名来实现这一目标。
所以查询应该如下所示:
DELETE orders.p
FROM orders.profile AS p
LEFT OUTER JOIN orders.qualified AS q
ON p.cust_id = q.cust_id
AND p.job_number = q.job_number
AND p.job_seg = q.job_seg
AND p.zip = q.zip
AND p.carrier_route = q.carrier_route
WHERE p.cust_id = {the cust_id in question}
AND p.job_number = {the job number in question}
and q.qualified = 0;