{"id":940,"date":"2011-02-16T15:04:53","date_gmt":"2011-02-16T13:04:53","guid":{"rendered":"http:\/\/sickel.net\/blogg\/?p=940"},"modified":"2011-05-05T22:06:38","modified_gmt":"2011-05-05T20:06:38","slug":"sql-setting-and-resetting-in-one-query","status":"publish","type":"post","link":"http:\/\/sickel.net\/blogg\/?p=940","title":{"rendered":"SQL &#8211; setting and resetting in one query"},"content":{"rendered":"<p>A colleague has a web application where a number of flags can be set or reset using checkboxses. These flags corresponds to rows in a table. When they have been altered, those who are set are returned from the browser, whereas those that are not set are not mentioned. <\/p>\n<p>The obious (imo) way of doing this is first to reset everyting:<\/p>\n<p><code>update settings set flag=0<\/code><\/p>\n<p>then set those returned with e.g.<\/p>\n<p><code>update settings set flag=1 where id in(2,3,4,7)<\/code><\/p>\n<p>but it is really possible to do it all in one go, using the sql if-function:<\/p>\n<p><code>update settings set flag=if(id in(2,3,4,7),1,0)<\/code><\/p>\n<p>This will set those with id in the in-clause to 1, all others to 0. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>A colleague has a web application where a number of flags can be set or reset using checkboxses. These flags corresponds to rows in a table. When they have been altered, those who are set are returned from the browser, &hellip; <a href=\"http:\/\/sickel.net\/blogg\/?p=940\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_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":""},"categories":[27],"tags":[],"class_list":["post-940","post","type-post","status-publish","format-standard","hentry","category-sql"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pnVtD-fa","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts\/940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=940"}],"version-history":[{"count":6,"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts\/940\/revisions"}],"predecessor-version":[{"id":1023,"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts\/940\/revisions\/1023"}],"wp:attachment":[{"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=940"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}