' on'中的多列条款

时间:2014-07-30 09:32:41

标签: mysql sql inner-join conditional-operator

我想使用以下MySQL语句,但我不确定它是否正确:

 Delete c 
 From tmp_customers c Inner Join salary s ON 
                    c.id = s.user_id And c.level = s.level

从tmp_customers表中删除所有具有正确定义薪水的客户(使用正确的客户级别进行回收)并分析剩余的客户。

语句执行不会出错,但我不确定该语句是否实现了目的。

我可以在'on'条件下使用多个条件吗?

1 个答案:

答案 0 :(得分:1)

是的,您的查询正确应该。改写为:

DELETE c 
FROM tmp_customers c
INNER JOIN salary s on (c.id = s.user_id AND c.level = s.level)

-- OR --
-- used a where clause below instead of on --
-- just to show it can also work without on using where --

DELETE c 
FROM tmp_customers c
INNER JOIN salary s
WHERE (c.id = s.user_id AND c.level = s.level)


答案:是的,您可以在 on 条件中使用多个条件。