iowatiger08
iowatiger08

Reputation: 1962

MySQL update single table with join

I have a values in table "REVIEW" that need to change REVIEW_STATUS from "UNDER_REVIEW" to "Abstain" based upon other records in the table that have the same REFERENCE_NUMBER , A specific REVIEW_TYPE and that REVIEW_STATUS is "ABSTAIN". The I have a sample set up in SQL Fiddle

http://sqlfiddle.com/#!2/8227f/1

I am able to query the tables for the records, but I am having difficulty getting the update query correct.

-- run   
UPDATE TABLE REVIEW AS REV1  
LEFT JOIN REVIEW AS REV2 
ON (REV1.REFERENCE_NUMBER=REV2.REFERENCE_NUMBER)
SET REV1.REVIEW_STATUS='ABSTAIN' 
WHERE 
REV1.REVIEW_TYPE ='QOC' 
AND 
REV1.REVIEW_STATUS='UNDER_REVIEW'
AND 
REV2.REVIEW_TYPE ='MED_NEC'
AND (REV2.REVIEW_STATUS ='ABSTAIN' )
;  

Your help is appreciated! Thank you!

Upvotes: 0

Views: 211

Answers (2)

iowatiger08
iowatiger08

Reputation: 1962

It was the word TABLE

UPDATE  REVIEW AS REV1  
LEFT JOIN REVIEW AS REV2 
ON (REV1.REFERENCE_NUMBER=REV2.REFERENCE_NUMBER)
SET REV1.REVIEW_STATUS='ABSTAIN' 
WHERE 
REV1.REVIEW_TYPE ='QOC' 
AND 
REV1.REVIEW_STATUS='UNDER_REVIEW'
AND 
REV2.REVIEW_TYPE ='MED_NEC'
AND (REV2.REVIEW_STATUS ='ABSTAIN' )
; 

Upvotes: 0

peterm
peterm

Reputation: 92785

Change

UPDATE TABLE REVIEW AS REV1 
...

to

UPDATE REVIEW AS REV1 
...

Updated SQLFiddle

Upvotes: 2

Related Questions