AND no SQL (Firebird)

Asked

Viewed 23 times

0

I have the following code:

UPDATE PRODUTOS SET categoria = '001' WHERE marca = '1774'

But there are over 400 brands.. I thought about using AND in Where to do it with multiple brands at once, but it won’t, and with one brand it only will. Is there any way to shorten it so it doesn’t go one by one?

  • 1

    If you use AND... a tag can be two different values at the same time?

  • 2

    Would not be OR (make = 1 OR mark=2 OR ...) or even IN (mark IN (1, 2, ...))?

1 answer

2

Use the clause IN

UPDATE PRODUTOS SET categoria = '001' WHERE marca IN ('1774', '1775', '1776')

You can also use a sub-select there to return the code of the tags you want, for example, if you have a tag-only table:

UPDATE PRODUTOS 
   SET categoria = '001' 
 WHERE marca IN (SELECT CODIGO
                   FROM MARCAS
                  WHERE TIPO = 1)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.