开发者

Multiple Query Writing in Single Query

I have two tables in Database , I need to select a field from one table and update it in another table with a condition where id is same .. Is it Possible to write in single que开发者_Python百科ry ???


This should work for you:

update storage 
    set storage.email = (select register.email
                           from register 
                           where register.id = storage.id)


Yeah it is, you could do this for example:

UPDATE Origin SET DesiredColumn = NewValue
FROM Origin
JOIN NewTable ON Origin.Id = NewTable.Id

And guess the column names were like DesiredColumn in the updating table and NewValue in the table that holds the new value.


Yes, this is possible, although the syntax depends on the type of SQL you are using.

Here is an example for T-SQL (for Microsoft SQL Server)

UPDATE
   S
SET
   Email = R.Email
FROM
   dbo.Register R
INNER JOIN dbo.Storage S
   ON S.RegisterID = R.RegisterID
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜