Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
144 views
in Technique[技术] by (71.8m points)

sql - Using UPDATE statement while using multiple WITH

I have a sql statement that returns records that I need and I am using several WITH clauses. I am trying to update one column within the statement.

WITH <name_a> AS (SELECT...),
     <name_b> AS (SELECT...using 'name_a'),
     <name_c> AS (SELECT...using 'name_b')
SELECT * from <name_c>

How would I write the statement if I just want to update a column in the final <name_c> output? Ex.

UPDATE name_c SET fav_color = 'blue' 

for all the records.

I tried just replacing the select with the update statement but I get 'Missing SELECT keyword'.

I found a similar question but it looks like this question focused on updating the value to what was returned from the select statement. Using "WITH" and "UPDATE" statements in the same SQL query

question from:https://stackoverflow.com/questions/65830641/using-update-statement-while-using-multiple-with

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...