Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...