7

I was wondering if you can do an Update with multiple conditions like so:

UPDATE participantes SET confirmado = 1 WHERE id = 19 AND id = 20 AND id = 21;

participantes -> Table

confirmado -> field of the table participantes.

1
  • 2
    In that case, no - you'd need id to be three different values. You can try WHERE id IN (19,20,21) to update multiple rows; or WHERE cond1=19 AND cond2=20 for checking different fields. Commented Apr 30, 2014 at 17:07

3 Answers 3

10

To accomplish what you're describing, I would, instead, use the IN clause:

UPDATE participantes SET confirmado = 1 WHERE id IN(19, 20, 21);
Sign up to request clarification or add additional context in comments.

1 Comment

Almost wrote this exactly, kudos
9

MySQL's AND clause will only work when ALL of the criteria are met. What you're looking for is OR. In the format that you provided:

UPDATE participantes SET confirmado = 1 WHERE id = 19 OR id = 20 OR id = 21;

Although, the above-noted IN (19, 20, 21) would be better for this specific use case.

Your original query was trying to look for a single row where id was simultaneously 19, 20, and 21, which would never happen.

Comments

0

How about this?

UPDATE participantes SET confirmado = 1 WHERE id >= 19 AND id != 50 AND id != 51;

1 Comment

I tried this (AND) multiple times and different query but it doesn't seem to work

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.