0

我在创建语句以删除具有多个字段连接的记录时遇到问题。我已经搜索并找到了许多解决方案,但仍然对我不起作用。

我有两个表: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;
4

2 回答 2

1

USING尝试不带语句的删除:

DELETE p FROM
orders.profile AS p
  LEFT OUTER JOIN orders.qualified AS q
  ON p.cust_id = q.cust_id ...

如果这不起作用,那么还有一些更根本的事情正在发生。

于 2012-07-10T23:51:01.143 回答
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; 
于 2012-07-11T18:08:53.883 回答