Update query using Subquery in Sql Server

后端 未结 5 1340
走了就别回头了
走了就别回头了 2020-12-02 07:14

I have a simple table Structure like this:

Table tempData

╔══════════╦═══════╗
║   NAME   ║ MARKS ║
╠══════════╬═══         


        
5条回答
  •  抹茶落季
    2020-12-02 07:35

    The title of this thread asks how a subquery can be used in an update. Here's an example of that:

    update [dbName].[dbo].[MyTable] 
    set MyColumn = 1 
    where 
        (
            select count(*) 
            from [dbName].[dbo].[MyTable] mt2 
            where
                mt2.ID > [dbName].[dbo].[MyTable].ID
                and mt2.Category = [dbName].[dbo].[MyTable].Category
        ) > 0
    

提交回复
热议问题