Pregunta

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?

¿Fue útil?

Solución

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));
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top