{"id":7030,"date":"2018-08-26T08:21:24","date_gmt":"2018-08-26T15:21:24","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=7030"},"modified":"2021-04-25T21:44:38","modified_gmt":"2021-04-26T04:44:38","slug":"mysql-control-flow-functions","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/","title":{"rendered":"MySQL Control Flow Functions and Expressions"},"content":{"rendered":"\n<p>The control flow functions allow you to add if-then-else logic to SQL queries without using the procedural code. The following show the most commonly used MySQL control flows functions:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/mysql-case-function\/\">CASE<\/a> &#8211; return the corresponding result in <code>THEN<\/code>&nbsp;branch if the condition in the <code>WHEN<\/code> branch is satisfied, otherwise, return the result in the <code>ELSE<\/code> branch.<\/li><li><a href=\"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/mysql-if-function\/\">IF<\/a> &#8211; return a value based on a given condition.<\/li><li><a title=\"MySQL IFNULL\" href=\"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/mysql-ifnull\/\">IFNULL<\/a>&#8211; return the first argument if it is not <code>NULL<\/code> , otherwise returns the second argument.<\/li><li><a title=\"MySQL NULLIF\" href=\"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/mysql-nullif\/\">NULLIF<\/a>&#8211; return&nbsp;<code>NULL<\/code> if the first argument is equal to the second argument, otherwise, returns the first argument.<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The control flow functions allow you to add if-then-else logic to SQL queries without using the procedural code.<\/p>\n","protected":false},"author":2,"featured_media":10064,"parent":0,"menu_order":16,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-7030","page","type-page","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MySQL Control Flow Functions Overview<\/title>\n<meta name=\"description\" content=\"The control flow functions allow you to add if-then-else logic to SQL queries without using the procedural code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL Control Flow Functions Overview\" \/>\n<meta property=\"og:description\" content=\"The control flow functions allow you to add if-then-else logic to SQL queries without using the procedural code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2021-04-26T04:44:38+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-control-flow-functions\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-control-flow-functions\\\/\",\"name\":\"MySQL Control Flow Functions Overview\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-control-flow-functions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-control-flow-functions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/mysql-control-functions.svg\",\"datePublished\":\"2018-08-26T15:21:24+00:00\",\"dateModified\":\"2021-04-26T04:44:38+00:00\",\"description\":\"The control flow functions allow you to add if-then-else logic to SQL queries without using the procedural code.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-control-flow-functions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-control-flow-functions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-control-flow-functions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/mysql-control-functions.svg\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/mysql-control-functions.svg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-control-flow-functions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL Control Flow Functions and Expressions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\",\"name\":\"MySQL Tutorial\",\"description\":\"A comprehensive MySQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mysqltutorial.org\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MySQL Control Flow Functions Overview","description":"The control flow functions allow you to add if-then-else logic to SQL queries without using the procedural code.","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:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/","og_locale":"en_US","og_type":"article","og_title":"MySQL Control Flow Functions Overview","og_description":"The control flow functions allow you to add if-then-else logic to SQL queries without using the procedural code.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/","og_site_name":"MySQL Tutorial","article_modified_time":"2021-04-26T04:44:38+00:00","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/","url":"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/","name":"MySQL Control Flow Functions Overview","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2021\/04\/mysql-control-functions.svg","datePublished":"2018-08-26T15:21:24+00:00","dateModified":"2021-04-26T04:44:38+00:00","description":"The control flow functions allow you to add if-then-else logic to SQL queries without using the procedural code.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2021\/04\/mysql-control-functions.svg","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2021\/04\/mysql-control-functions.svg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL Control Flow Functions and Expressions"}]},{"@type":"WebSite","@id":"https:\/\/www.mysqltutorial.org\/#website","url":"https:\/\/www.mysqltutorial.org\/","name":"MySQL Tutorial","description":"A comprehensive MySQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mysqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/7030","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/comments?post=7030"}],"version-history":[{"count":0,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/7030\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media\/10064"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=7030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}