{"id":2867,"date":"2015-08-19T18:42:23","date_gmt":"2015-08-19T22:42:23","guid":{"rendered":"http:\/\/sqlity.net\/en\/?p=2867"},"modified":"2015-08-19T20:55:15","modified_gmt":"2015-08-20T00:55:15","slug":"update-from-select","status":"publish","type":"post","link":"https:\/\/sqlity.net\/en\/2867\/update-from-select\/","title":{"rendered":"<span class=\"post-emph1\">The Hidden SQL Server Gem:<\/span> <span class=\"post-emph2\">UPDATE from SELECT<\/span>"},"content":{"rendered":"<div class=\"stretch-post\">\n<h2><span class=\"post-emph1\">3 Simple Ways<\/span> to use <span class=\"post-emph2\">UPDATE from SELECT<\/span> making Your Job easier<\/h2>\n<p>\nYou probably have been in this situation before: You needed to update the data in one table using information stored in another table. I often meet people who have not heard of the powerful <span class=\"tt\">UPDATE<\/span> from <span class=\"tt\">SELECT<\/span> solution SQL Server provides for this problem. In fact, I struggled with this problem for quite some time before I found out about this gem.\n<\/p>\n<p>\nIn the following lines, I am going to show you three tricks that have made my life simpler on many occasions. For that, we first need two tables:\n<\/p>\n<p>\n<a href=\"http:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/The_Customers_Table.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/The_Customers_Table.jpg\" alt=\"The Customers Table\" width=\"768\" height=\"468\" class=\"aligncenter size-full wp-image-2871\" srcset=\"https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/The_Customers_Table.jpg 768w, https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/The_Customers_Table-300x183.jpg 300w, https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/The_Customers_Table-150x91.jpg 150w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a>\n<\/p>\n<p>\n<a href=\"http:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/The_Orders_Table.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/The_Orders_Table.jpg\" alt=\"The Orders Table\" width=\"768\" height=\"468\" class=\"aligncenter size-full wp-image-2869\" srcset=\"https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/The_Orders_Table.jpg 768w, https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/The_Orders_Table-300x183.jpg 300w, https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/The_Orders_Table-150x91.jpg 150w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a>\n<\/p>\n<p>\nIf you want to follow along, you can get the script here: <a href=\"https:\/\/gist.github.com\/sqlity\/2e5308c6ad989cf40574\">The Hidden SQL Server Gem - UPDATE from SELECT.sql<\/a>\n<\/p>\n<h3><img decoding=\"async\" src=\"http:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/Small-green-Numbers-for-blog-1.png\" alt=\"1)\" style=\"width:30px;\" \/>Develop your <span class=\"post-emph2\">UPDATE from a SELECT<\/span><\/h3>\n<p>\nNow that we have the environment set up, let's dive into how to make this work. Before I show you the multi-table solution, let me demonstrate the simplest form of the <span class=\"tt\">UPDATE FROM<\/span> syntax and show you a simple trick to make developing your <span class=\"tt\">UPDATE<\/span> statements really simple, by writing a <span class=\"tt\">SELECT<\/span> statement first and then turning it into an update by deleting two characters. Intrigued?\n<\/p>\n<p>\nThe <span class=\"tt\">dbo.Orders<\/span> table contains and <span class=\"tt\">is_archived<\/span> column. This is used to archive orders older than 90 days. However, we have the additional rule that orders that have not yet been paid or shipped cannot be archived. (In this example, the <span class=\"tt\">is_archived<\/span> column has no physical effect. See my SQL Server Pro article <a href=\"http:\/\/sqlmag.com\/database-administration\/using-table-partitions-archive-old-data-oltp-environments\">Using Table Partitions to Archive Old Data in OLTP Environments<\/a> if you are interested in how to turn the <span class=\"tt\">is_archived<\/span> column into an actual archive switch.)\n<\/p>\n<p>\nA <span class=\"tt\">SELECT<\/span> statement to return the archive-able records would look like this:\n<\/p>\n<div>\n[sql]\nSELECT *<br \/>\n  FROM dbo.Orders AS O<br \/>\n WHERE O.order_date &lt; DATEADD(DAY,-90,SYSDATETIME())<br \/>\n   AND O.is_paid = 1<br \/>\n   AND O.is_shipped = 1;<br \/>\n[\/sql]\n<\/div>\n<p>\nNow let's add a little magic to it:\n<\/p>\n<div>\n[sql]\n--UPDATE O SET \/*<br \/>\nSELECT *, -- *\/<br \/>\n    is_archived = 1<br \/>\n  FROM dbo.Orders AS O<br \/>\n WHERE O.order_date &lt; DATEADD(DAY,-90,SYSDATETIME())<br \/>\n   AND O.is_paid = 1<br \/>\n   AND O.is_shipped = 1;<br \/>\n[\/sql]\n<\/div>\n<p>\nThis is still a simple <span class=\"tt\">SELECT<\/span> statement. We just added two comments and an additional column. That additional column is using the uncommon alias syntax <span class=\"tt\">name = value<\/span> with is equivalent to the more common <span class=\"tt\">value AS name<\/span> syntax.\n<\/p>\n<p>\nThe beauty of this lies in the fact that I can turn this select into a syntactically correct <span class=\"tt\">UPDATE<\/span> statement, just by removing the two dashes in front of the <span class=\"tt\">UPDATE<\/span> keyword:\n<\/p>\n<div>\n[sql]\nUPDATE O SET \/*<br \/>\nSELECT *, -- *\/<br \/>\n    is_archived = 1<br \/>\n  FROM dbo.Orders AS O<br \/>\n WHERE O.order_date &lt; DATEADD(DAY,-90,SYSDATETIME())<br \/>\n   AND O.is_paid = 1<br \/>\n   AND O.is_shipped = 1;<br \/>\n[\/sql]\n<\/div>\n<p>\nThis updates the <span class=\"tt\">dbo.Orders<\/span> table just like and <span class=\"tt\">UPDATE dbo.Orders SET\u2026<\/span> statement would, because the <span class=\"tt\">dbo.Orders<\/span> table is aliased as <span class=\"tt\">O<\/span> and the <span class=\"tt\">UPDATE<\/span> is referencing that same <span class=\"tt\">O<\/span> alias.\n<\/p>\n<h3><img decoding=\"async\" src=\"http:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/Small-green-Numbers-for-blog-2.png\" alt=\"2)\" style=\"width:30px;\" \/>Adding a <span class=\"post-emph2\">JOIN to the UPDATE<\/span> statement<\/h3>\n<p>\nThe question that let us here was how we can use data in a one table to update another table. Wouldn't it be nice if we could just \"<span class=\"tt\">JOIN<\/span>\"? Good news: The above syntax allows us to do just that.\n<\/p>\n<p>\nRecently an <span class=\"tt\">order_count<\/span> column was added to the <span class=\"tt\">dbo.Customers<\/span> table. Our job now is to value that column correctly based on the actual orders each customer has placed. We start out again by writing a select first:\n<\/p>\n<div>\n[sql]\n--UPDATE C SET \/*<br \/>\nSELECT *, -- *\/<br \/>\n    order_count = OA.cnt<br \/>\n  FROM dbo.Customers AS C<br \/>\n  JOIN(<br \/>\n       SELECT O.customer_id,<br \/>\n              COUNT(1) cnt<br \/>\n         FROM dbo.Orders AS O<br \/>\n        GROUP BY O.customer_id<br \/>\n      )OA<br \/>\n    ON C.customer_id = OA.customer_id;<br \/>\n[\/sql]\n<\/div>\n<p>\nOnce the <span class=\"tt\">SELECT<\/span> statement returns the correct results, it is easy to switch it to <span class=\"tt\">UPDATE<\/span>:\n<\/p>\n<div>\n[sql]\nUPDATE C SET \/*<br \/>\nSELECT *, -- *\/<br \/>\n    order_count = OA.cnt<br \/>\n  FROM dbo.Customers AS C<br \/>\n  JOIN(<br \/>\n       SELECT O.customer_id,<br \/>\n              COUNT(1) cnt<br \/>\n         FROM dbo.Orders AS O<br \/>\n        GROUP BY O.customer_id<br \/>\n      )OA<br \/>\n    ON C.customer_id = OA.customer_id;<br \/>\n[\/sql]\n<\/div>\n<p>\nBecause of the use of the alias <span class=\"tt\">C<\/span>, SQL Server knows to update the <span class=\"tt\">dbo.Customers<\/span> table while pulling in necessary information from other table(s) referenced in the statement.\n<\/p>\n<h3><img decoding=\"async\" src=\"http:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/Small-green-Numbers-for-blog-3.png\" alt=\"3)\" style=\"width:30px;\" \/>Using <span class=\"post-emph2\">UPDATE with a CTE<\/span><\/h3>\n<p>\nIf CTEs are your thing, you can even go a step further with this. As long as SQL Server can easily determine what you are intending to update, you can actually \"UPDATE\" a CTE directly using a very similar syntax:\n<\/p>\n<div>\n[sql]\nWITH order_counts AS<br \/>\n(<br \/>\n  SELECT O.customer_id,<br \/>\n         COUNT(1) cnt<br \/>\n    FROM dbo.Orders AS O<br \/>\n   GROUP BY O.customer_id<br \/>\n),<br \/>\ncustomer_order_counts AS<br \/>\n(<br \/>\n  SELECT<br \/>\n      C.customer_id,<br \/>\n      C.name,<br \/>\n      C.order_count,<br \/>\n      OC.cnt new_order_cnt<br \/>\n    FROM dbo.Customers AS C<br \/>\n    JOIN order_counts AS OC<br \/>\n      ON C.customer_id = OC.customer_id<br \/>\n)<br \/>\nUPDATE COC SET \/*<br \/>\nSELECT *, -- *\/<br \/>\n    order_count = COC.new_order_cnt<br \/>\n  FROM customer_order_counts AS COC;<br \/>\n[\/sql]\n<\/div>\n<p>\nHe only thing you cannot do with any of the above statements, is to update data in two tables at the same time.\n<\/p>\n<h3><img decoding=\"async\" src=\"http:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/Small-orange-Numbers-for-blog-.png\" alt=\"!)\" style=\"width:30px;\" \/>A Word of <span class=\"post-emph2\">Caution<\/span><\/h3>\n<p>\nThis syntax provides us with a very powerful way to write <span class=\"tt\">UPDATE<\/span> statements that require data from more than one table. However, be careful not to write code that shows random behavior. Take a look at this <span class=\"tt\">UPDATE<\/span> statement:\n<\/p>\n<p>\n<a href=\"http:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/Fragile_UPDATE.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/Fragile_UPDATE.jpg\" alt=\"Fragile UPDATE FROM SELECT\" width=\"768\" height=\"468\" class=\"aligncenter size-full wp-image-2870\" srcset=\"https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/Fragile_UPDATE.jpg 768w, https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/Fragile_UPDATE-300x183.jpg 300w, https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/Fragile_UPDATE-150x91.jpg 150w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a>\n<\/p>\n<p>\nJust like the highlighted <span class=\"tt\">SELECT<\/span> returns a customer with multiple orders multiple times, the  <span class=\"tt\">UPDATE<\/span> would happily update each customer multiple times, each time overwriting the prior change. Only the last change would persist.\n<\/p>\n<p>\nThe problem with that is that there is no guarantee in which order that happens. The order is dependent on the execution plan chosen and can change any time. So while the above statement might actually result in the last order date being written in your tests, it likely will execute in a different order once the statement encounters a large amount of data. This will lead to hard to debug problems, so pay attention to this possibility, when writing your <span class=\"tt\">UPDATE FROM SELECT<\/span> statements.\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes we need to update data in one table based on the contents of one or more other tables. Discover how the UPDATE from SELECT variation of SQL Server&#8217;s UPDATE statement provides an easy way to achieve this.<\/p>\n<p> <a href=\"https:\/\/sqlity.net\/en\/2867\/update-from-select\/\">[more&#8230;]<\/a><\/p>\n","protected":false},"author":3,"featured_media":2879,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[29,5,124,23],"tags":[15,268,267],"class_list":["post-2867","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-fundamentals","category-general","category-queries","category-t-sql-statements","tag-sql-server","tag-tipstricks","tag-update"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>The Hidden SQL Server Gem: UPDATE from SELECT - sqlity.net<\/title>\n<meta name=\"description\" content=\"Discover why the UPDATE from SELECT variation of SQL Server&#039;s UPDATE statement is a powerful way to apply table updates based on data in another table.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/sqlity.net\/en\/2867\/update-from-select\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Hidden SQL Server Gem: UPDATE from SELECT - sqlity.net\" \/>\n<meta property=\"og:description\" content=\"Discover why the UPDATE from SELECT variation of SQL Server&#039;s UPDATE statement is a powerful way to apply table updates based on data in another table.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/sqlity.net\/en\/2867\/update-from-select\/\" \/>\n<meta property=\"og:site_name\" content=\"sqlity.net\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/sqlity.net\" \/>\n<meta property=\"article:published_time\" content=\"2015-08-19T22:42:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-08-20T00:55:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/UPDATE_from_SELECT.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"768\" \/>\n\t<meta property=\"og:image:height\" content=\"468\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sebastian Meine\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@sqlity\" \/>\n<meta name=\"twitter:site\" content=\"@sqlity\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sebastian Meine\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2867\\\/update-from-select\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2867\\\/update-from-select\\\/\"},\"author\":{\"name\":\"Sebastian Meine\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#\\\/schema\\\/person\\\/bcffd8c572bc2f1bd10fdba80135e53c\"},\"headline\":\"The Hidden SQL Server Gem: UPDATE from SELECT\",\"datePublished\":\"2015-08-19T22:42:23+00:00\",\"dateModified\":\"2015-08-20T00:55:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2867\\\/update-from-select\\\/\"},\"wordCount\":1078,\"commentCount\":1,\"image\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2867\\\/update-from-select\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/sqlity.net\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/UPDATE_from_SELECT.jpg\",\"keywords\":[\"SQL Server\",\"Tips&amp;Tricks\",\"UPDATE\"],\"articleSection\":[\"Fundamentals\",\"General\",\"Queries\",\"T-SQL Statements\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/sqlity.net\\\/en\\\/2867\\\/update-from-select\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2867\\\/update-from-select\\\/\",\"url\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2867\\\/update-from-select\\\/\",\"name\":\"The Hidden SQL Server Gem: UPDATE from SELECT - sqlity.net\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2867\\\/update-from-select\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2867\\\/update-from-select\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/sqlity.net\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/UPDATE_from_SELECT.jpg\",\"datePublished\":\"2015-08-19T22:42:23+00:00\",\"dateModified\":\"2015-08-20T00:55:15+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#\\\/schema\\\/person\\\/bcffd8c572bc2f1bd10fdba80135e53c\"},\"description\":\"Discover why the UPDATE from SELECT variation of SQL Server's UPDATE statement is a powerful way to apply table updates based on data in another table.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2867\\\/update-from-select\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/sqlity.net\\\/en\\\/2867\\\/update-from-select\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2867\\\/update-from-select\\\/#primaryimage\",\"url\":\"https:\\\/\\\/sqlity.net\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/UPDATE_from_SELECT.jpg\",\"contentUrl\":\"https:\\\/\\\/sqlity.net\\\/wp-content\\\/uploads\\\/2015\\\/08\\\/UPDATE_from_SELECT.jpg\",\"width\":768,\"height\":468},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2867\\\/update-from-select\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/sqlity.net\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The Hidden SQL Server Gem: UPDATE from SELECT\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/sqlity.net\\\/en\\\/\",\"name\":\"sqlity.net\",\"description\":\"Quality for SQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/sqlity.net\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#\\\/schema\\\/person\\\/bcffd8c572bc2f1bd10fdba80135e53c\",\"name\":\"Sebastian Meine\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g\",\"caption\":\"Sebastian Meine\"},\"sameAs\":[\"http:\\\/\\\/sqlity.net\",\"https:\\\/\\\/x.com\\\/sqlity\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The Hidden SQL Server Gem: UPDATE from SELECT - sqlity.net","description":"Discover why the UPDATE from SELECT variation of SQL Server's UPDATE statement is a powerful way to apply table updates based on data in another table.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/sqlity.net\/en\/2867\/update-from-select\/","og_locale":"en_US","og_type":"article","og_title":"The Hidden SQL Server Gem: UPDATE from SELECT - sqlity.net","og_description":"Discover why the UPDATE from SELECT variation of SQL Server's UPDATE statement is a powerful way to apply table updates based on data in another table.","og_url":"https:\/\/sqlity.net\/en\/2867\/update-from-select\/","og_site_name":"sqlity.net","article_publisher":"https:\/\/www.facebook.com\/sqlity.net","article_published_time":"2015-08-19T22:42:23+00:00","article_modified_time":"2015-08-20T00:55:15+00:00","og_image":[{"width":768,"height":468,"url":"https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/UPDATE_from_SELECT.jpg","type":"image\/jpeg"}],"author":"Sebastian Meine","twitter_card":"summary_large_image","twitter_creator":"@sqlity","twitter_site":"@sqlity","twitter_misc":{"Written by":"Sebastian Meine","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/sqlity.net\/en\/2867\/update-from-select\/#article","isPartOf":{"@id":"https:\/\/sqlity.net\/en\/2867\/update-from-select\/"},"author":{"name":"Sebastian Meine","@id":"https:\/\/sqlity.net\/en\/#\/schema\/person\/bcffd8c572bc2f1bd10fdba80135e53c"},"headline":"The Hidden SQL Server Gem: UPDATE from SELECT","datePublished":"2015-08-19T22:42:23+00:00","dateModified":"2015-08-20T00:55:15+00:00","mainEntityOfPage":{"@id":"https:\/\/sqlity.net\/en\/2867\/update-from-select\/"},"wordCount":1078,"commentCount":1,"image":{"@id":"https:\/\/sqlity.net\/en\/2867\/update-from-select\/#primaryimage"},"thumbnailUrl":"https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/UPDATE_from_SELECT.jpg","keywords":["SQL Server","Tips&amp;Tricks","UPDATE"],"articleSection":["Fundamentals","General","Queries","T-SQL Statements"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/sqlity.net\/en\/2867\/update-from-select\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/sqlity.net\/en\/2867\/update-from-select\/","url":"https:\/\/sqlity.net\/en\/2867\/update-from-select\/","name":"The Hidden SQL Server Gem: UPDATE from SELECT - sqlity.net","isPartOf":{"@id":"https:\/\/sqlity.net\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/sqlity.net\/en\/2867\/update-from-select\/#primaryimage"},"image":{"@id":"https:\/\/sqlity.net\/en\/2867\/update-from-select\/#primaryimage"},"thumbnailUrl":"https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/UPDATE_from_SELECT.jpg","datePublished":"2015-08-19T22:42:23+00:00","dateModified":"2015-08-20T00:55:15+00:00","author":{"@id":"https:\/\/sqlity.net\/en\/#\/schema\/person\/bcffd8c572bc2f1bd10fdba80135e53c"},"description":"Discover why the UPDATE from SELECT variation of SQL Server's UPDATE statement is a powerful way to apply table updates based on data in another table.","breadcrumb":{"@id":"https:\/\/sqlity.net\/en\/2867\/update-from-select\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/sqlity.net\/en\/2867\/update-from-select\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/sqlity.net\/en\/2867\/update-from-select\/#primaryimage","url":"https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/UPDATE_from_SELECT.jpg","contentUrl":"https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/UPDATE_from_SELECT.jpg","width":768,"height":468},{"@type":"BreadcrumbList","@id":"https:\/\/sqlity.net\/en\/2867\/update-from-select\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/sqlity.net\/en\/"},{"@type":"ListItem","position":2,"name":"The Hidden SQL Server Gem: UPDATE from SELECT"}]},{"@type":"WebSite","@id":"https:\/\/sqlity.net\/en\/#website","url":"https:\/\/sqlity.net\/en\/","name":"sqlity.net","description":"Quality for SQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/sqlity.net\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/sqlity.net\/en\/#\/schema\/person\/bcffd8c572bc2f1bd10fdba80135e53c","name":"Sebastian Meine","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g","caption":"Sebastian Meine"},"sameAs":["http:\/\/sqlity.net","https:\/\/x.com\/sqlity"]}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/sqlity.net\/wp-content\/uploads\/2015\/08\/UPDATE_from_SELECT.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2wXuw-Kf","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/posts\/2867","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/comments?post=2867"}],"version-history":[{"count":0,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/posts\/2867\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/media\/2879"}],"wp:attachment":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/media?parent=2867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/categories?post=2867"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/tags?post=2867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}