0

I have a list of values that I want to match with the where clause to update a flag.

(col1, col2, col3)

(1, 2, 3)

(2, 3, 4)

(3, 4, 5)

If the filtering list were made by only one column I would have done this way:

update mytable 
set flag=1
where col1 in ('1','2','3','5','8','13');

Would this query be fit for my purpose?

update mytable 
set flag=1
where col1 in ('1','2','3')
and col2 in ('2','3','4')
and col3 in ('3','4','5');

If the table had a record (1,3,5) the query would update the flag but the filtering list would not be considered correctly.

Is it possible to use the where clause with all of the columns of my filtering list? For example

where (col1, col2, col3) in (???)

1 Answer 1

2

You can use IN to compare row constructors (see here).

The following should work:

UPDATE mytable
SET flag=1
WHERE (col1, col2, col3) IN ((1, 2, 3), (2, 3, 4), ...);

But as written here it might not be the fastest solution.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.