문제

This should be relatively simple. I dug around the MySql docs and couldn't find relevant infos.

The scenario is simple. I have a table with 3 columns. All are composite unique keys, in that, all keys together must be unique to be a valid row.

How can I use DELETE NOT IN with this setup?

I tried something like:

DELETE FROM my_table WHERE (col1,col2,col3) NOT IN (val1,val2,val3), (val4,val5,val6)

As you can see, I want to match the sets of values, not necessarily the values themselves.

Thoughts?

도움이 되었습니까?

해결책

IN or NOT IN must be followed by a single list. When comparing multiple columns, the items in the list are themselves parenthesized lists. So:

DELETE FROM my_table
WHERE (col1,col2,col3) NOT IN ((val1,val2,val3), (val4,val5,val6));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top