Why did this query mess my db table?

Just ran this query and it has made the value in all recors in 1 column, the same. why did it do that?


update statistics
set Domain_Viewed = 'example.com'
where Domain_Viewed = ('www.example.com' or 'http://www.example.com')


bazz

Your query is equivalent to:

UPDATE statistics
SET Domain_Viewed = 'example.com'
WHERE Domain_Viewed = 'www.example.com'
OR TRUE

Because a literal string when considered as a boolean is true, resulting in that query matching all rows. You can’t omit the field you’re comparing to, the parentheses don’t create that effect.

There are two correct forms for what you meant:

UPDATE statistics
SET Domain_Viewed = 'example.com'
WHERE Domain_Viewed = 'www.example.com' 
OR Domain_Viewed = 'http://www.example.com'
UPDATE statistics
SET Domain_Viewed = 'example.com'
WHERE Domain_Viewed  IN ('www.example.com', 'http://www.example.com')

Thanks Dan. That’s a mistake I won’t make again, in a hurry :nono:

bazz