0

I am trying to update records based on a secondary statement but i dont know how to link them together.

UPDATE WEBSITE SET CMS_ID = 99
SELECT * 
FROM website
WHERE is_scanned =  'yes'
AND cms_id =0

I want to update table website set the colum cms_id to 99 where all websites is_scanned = yes and cms_id = 0

will my query work?

David Garcia
  • 3,056
  • 18
  • 55
  • 90

2 Answers2

2

This query doesn't work ?

UPDATE website SET cmd_id = 99
WHERE is_scanned = 'yes' AND cms_id = 0;
Yang
  • 7,712
  • 9
  • 48
  • 65
slig36
  • 187
  • 3
  • 13
1

I think this accomplishes the goal you stated and should work in most databases:

UPDATE WEBSITE SET CMS_ID = 99
WHERE is_scanned =  'yes'
AND cms_id =0

The SELECT FROM is not required unless joins between different records or tables are important to the goal of the update. Here are some other examples for SQL Server

Community
  • 1
  • 1
dewww
  • 21
  • 2