0

So, I have to write a sql script to update 2 values on the same columns with a different ID from an ITEM table. Here is what I write:

UPDATE       ITEM
SET          ArtistName = 'Rex Baker'
WHERE        ItemNumber = 2
     AND     ItemNumber = 4;

However, it does not work at all. Can anyone tell me what I did wrong ? and how can I fix it ? Thank you

6
  • 2
    what you are saying is that the item must have an ItemNumber of 2 AND 4... rather than 2 OR 4. Commented Oct 4, 2013 at 8:06
  • I figured out how to do it. Basically, in the WHERE clause, I should put ItemNumber IN (2, 4); Commented Oct 4, 2013 at 8:08
  • @Secret Squirrel: So you can say OR instead of AND, and it works ? PS: I tried OR and it works too ;) Commented Oct 4, 2013 at 8:08
  • 1
    @user2383193 The AND means that both conditions have to be met at the same time. WHERE (ItemNumber = 2 AND ItemNumber = 4) is an equivalent of your version. So, your item number will never have 2 different values on the same row, and thus nothing will happen in your script. I hope this shed some light on the question. Commented Oct 4, 2013 at 8:09
  • @user2383193 Using OR means that ONLY 1 condition has to be met by the record. So, if your row has either 2 or 4 in their ItemNumber column, then it will get updated. Commented Oct 4, 2013 at 8:12

1 Answer 1

8

Use or or in

UPDATE   ITEM
SET      ArtistName = 'Rex Baker'
WHERE    ItemNumber = 2
OR       ItemNumber = 4;

UPDATE   ITEM
SET      ArtistName = 'Rex Baker'
WHERE    ItemNumber IN (2,4);
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.