OPMendeavor
OPMendeavor

Reputation: 460

Multiple columns in 'on' clause

I would like to use the following MySQL statement but I'm not very sure if it is correct:

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

to remove from the tmp_customers table all customers with correct defined salary (recore with the correct customer level) and analyze the remaining one.

The statement execution doesn't give error but I'm not sure the statement realizes the purpose.

Can I use multiple conditions in the 'on' condition?

Upvotes: 0

Views: 62

Answers (1)

Parag Tyagi
Parag Tyagi

Reputation: 8960

Yes your query is correct and should work. Rewritten as:

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)


Answer: Yes you can use multiple conditions in the on condition.

Upvotes: 1

Related Questions