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
353 views
in Technique[技术] by (71.8m points)

sql - Update query statement

I found out something strange which works

Update **X** SET field = 'bla'
from **X**

..which doesn't really make sense


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

1 Answer

0 votes
by (71.8m points)

This general syntax is usually used for joining tables when updating (i.e., you want to update column c1 in table t1 based on column c2 in table t2). The general for is

UPDATE 
    t1
SET 
    t1.c1 = t2.c2, -- Just an example
    t1.c3 = 'something else' -- etc...
FROM 
    t1
[INNER | LEFT] JOIN t2 ON join_condition

On you example, you don't have a join clause, so it may look a bit funny, but as you noted, this is valid syntax.


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

...