{"id":94523,"date":"2020-09-16T11:00:00","date_gmt":"2020-09-16T08:00:00","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=94523"},"modified":"2022-02-24T11:45:42","modified_gmt":"2022-02-24T09:45:42","slug":"sql-case-statement-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/","title":{"rendered":"SQL CASE Statement Example"},"content":{"rendered":"<p>This example will focus on the SQL Case Statement.<\/p>\n<p>In any programming language, you would know that the control statements are the most essential part of the programming language. Just like <strong>if-else<\/strong> in any of the programming languages, SQL also has the control statements. <\/p>\n<h2 class=\"wp-block-heading\" id=\"h-1-about-sql-case-statement\">1. About SQL CASE Statement <\/h2>\n<p>There will be a list of conditions, which can either be true or false. What the <strong>CASE<\/strong> statement does is that it goes through every condition one by one, and returns only the value for the first true statement. <\/p>\n<p>If there is no statement true, then it moves onto the else part. And, if even the else part is false, then it returns <strong>NULL<\/strong>. <\/p>\n<h2 class=\"wp-block-heading\" id=\"h-2-sql-case-syntax\">2. SQL CASE Syntax<\/h2>\n<p>The <strong>SQL CASE<\/strong> Syntax is given as follows: <\/p>\n<div class=\"wp-block-group\">\n<div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT CASE expr\nWHEN expr1 THEN X\nWhen expr2 THEN Y\n...\nELSE Z\nEND AS column_name\n<\/pre>\n<\/div>\n<p>Here, <strong>expr<\/strong>, <strong>expr1<\/strong>, and <strong>expr2 <\/strong>represent expressions (conditions), while <strong>X<\/strong>, <strong>Y<\/strong>, and <strong>Z<\/strong> represent the statements that need to be executed when their respective conditions are true. <\/p>\n<p>For example: if <strong>expr1<\/strong> is true, then <strong>X <\/strong>will be returned. If <strong>expr2<\/strong> is true, then <strong>Y<\/strong> will be returned. And, if-else is true, then <strong>Z<\/strong> will be returned. If none of the expressions\/conditions match to true, then <strong>NULL<\/strong> will be returned. <\/p>\n<\/div>\n<\/div>\n<p><strong>Note:<\/strong><\/p>\n<ul class=\"wp-block-list\">\n<li>You can have many expressions, i.e. conditions to check.<\/li>\n<li><strong>CASE<\/strong> Statement can be used with various other clauses like the <strong>Order By<\/strong> Clause, or the <strong>Group By<\/strong> Clause. <\/li>\n<\/ul>\n<p>Syntax to select particular columns, and using <strong>SQL CASE<\/strong> statement is as follows:<\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT column1, column2 CASE expr\nWHEN expr1 THEN X\nWhen expr2 THEN Y\n...\nELSE Z\nEND AS column_name\n<\/pre>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-3-sql-case-example\">3. SQL CASE Example<\/h2>\n<p>Let us now see all the different use-cases of the <strong>SQL CASE<\/strong> statement. <\/p>\n<h3 class=\"wp-block-heading\" id=\"h-3-1-creating-the-table-insert-sample-data-into-the-table\">3.1 Creating the table &amp; Insert sample data into the table<\/h3>\n<p>Let us create a table &#8211; <strong>student<\/strong> &#8211; with the columns as follows: roll number, name, and gender.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"359\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case-1024x359.jpg\" alt=\"SQL CASE - data inserted\" class=\"wp-image-94672\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case-1024x359.jpg 1024w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case-300x105.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case-768x269.jpg 768w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case.jpg 1096w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Table student-created &amp; data inserted<\/figcaption><\/figure>\n<p>Now, using the select statement, you can see the data that has been successfully inserted into the table.<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"190\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case3-1024x190.jpg\" alt=\"SQL CASE - Data inserted into the student table\" class=\"wp-image-94675\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case3-1024x190.jpg 1024w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case3-300x56.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case3-768x142.jpg 768w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case3.jpg 1080w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Data inserted into the student table<\/figcaption><\/figure>\n<h3 class=\"wp-block-heading\" id=\"h-3-2-sql-case-example\">3.2 SQL CASE Example<\/h3>\n<p>Let us segregate the rows with gender value &#8216;<strong>m<\/strong>&#8216; should correspond to &#8216;<strong>Male<\/strong>&#8216; while segregating the rows with gender value &#8216;<strong>f<\/strong>&#8216; should correspond to &#8216;<strong>Female&#8217;<\/strong>. <\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"471\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case2-1024x471.jpg\" alt=\"\" class=\"wp-image-94674\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case2-1024x471.jpg 1024w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case2-300x138.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case2-768x353.jpg 768w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case2.jpg 1080w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>SQL Case Statement is used.<\/figcaption><\/figure>\n<p>You can see the <strong>genderDetail <\/strong>column comprising of the values &#8216;<strong>MALE<\/strong>&#8216; and &#8216;<strong>FEMALE<\/strong>&#8216;, and compare it with the table below that to see the values of the gender column. <\/p>\n<h3 class=\"wp-block-heading\" id=\"h-3-3-sql-case-with-update-statement\">3.3 SQL CASE with UPDATE statement <\/h3>\n<p>Let us now use the update statement as well as the <strong>SQL CASE<\/strong> statement together. We are going to change the values of gender from lowercase to uppercase. <\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"372\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_cas4-1024x372.jpg\" alt=\"\" class=\"wp-image-94677\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_cas4-1024x372.jpg 1024w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_cas4-300x109.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_cas4-768x279.jpg 768w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_cas4.jpg 1100w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>SQL CASE and Update Statement<\/figcaption><\/figure>\n<p>You can clearly see that the gender column now has uppercase characters. The changes are made to the gender column since we did not create an alias.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-3-4-sql-case-with-group-by-clause\">3.4 SQL CASE with GROUP BY Clause<\/h3>\n<p>We can also use the<strong> SQL CASE<\/strong> statement with the <strong>GROUP BY<\/strong> Clause. In this case, we are going to group the students by their roll number. For roll numbers less than 10, they will be allocated &#8216;<strong>FRONT SEAT<\/strong>&#8216;. While for the roll numbers greater than or equal to 10, they will be allocated &#8216;<strong>BACK SEAT<\/strong>&#8216;. <\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"403\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case6-1024x403.jpg\" alt=\"SQL CASE - GROUP BY Clause\" class=\"wp-image-94684\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case6-1024x403.jpg 1024w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case6-300x118.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case6-768x302.jpg 768w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case6.jpg 1106w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>SQL CASE and GROUP BY Clause<\/figcaption><\/figure>\n<p>As a result of the query, you can see that the seats have been allocated to the students on the basis of the roll number.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-3-5-sql-case-with-order-by-clause\">3.5 SQL CASE with ORDER BY Clause<\/h3>\n<p>Now, we will use the<strong> SQL CASE <\/strong>statement with the <strong>ORDER BY<\/strong> clause. In this case, we have sorted the females with descending order of their roll numbers, while the males with the ascending order of their names. <\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1013\" height=\"317\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case5.jpg\" alt=\"SQL CASE - ORDER BY Clause\" class=\"wp-image-94683\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case5.jpg 1013w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case5-300x94.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/JCG_case5-768x240.jpg 768w\" sizes=\"(max-width: 1013px) 100vw, 1013px\" \/><figcaption>SQL CASE and ORDER BY Clause<\/figcaption><\/figure>\n<p>Here, you see that the female is ordered first since there is only 1 female in the table data. Then subsequently, both the males are ordered in the ascending order of their names.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-3-6-sql-case-in-a-having-clause\">3.6  SQL CASE in a HAVING Clause <\/h3>\n<p>Now, we will use the<strong> SQL CASE <\/strong>statement in a HAVING clause. In this case, we inserted three more records.  We use group by clause at the gender column and restrict the record count for female set it as 1, while for the male set as 4.  <\/p>\n<p><span style=\"text-decoration: underline\"><em>case in having<\/em><\/span><\/p>\n<pre class=\"wp-block-preformatted brush:sql\">insert into student values(100,'Allen','m');\ninsert into student values(122,'Amy','f');\ninsert into student values(221,'Arun','m');\nmysql&gt; select * from student;\n+--------+-------+--------+\n| rollno | name  | gender |\n+--------+-------+--------+\n|      1 | alex  | M      |\n|     12 | tina  | F      |\n|     22 | amex  | M      |\n|    100 | Allen | m      |\n|    122 | Amy   | f      |\n|    221 | Arun  | m      |\n+--------+-------+--------+\n6 rows in set (0.00 sec)\n\nmysql&gt; select gender, count(*) from student group by gender ;\n+--------+----------+\n| gender | count(*) |\n+--------+----------+\n| M      |        4 |\n| F      |        2 |\n+--------+----------+\n2 rows in set (0.00 sec)\nmysql&gt; SELECT Gender,  COUNT(*)\n    -&gt; FROM student\n    -&gt; GROUP BY Gender\n    -&gt; HAVING COUNT(*) &gt;\n    -&gt;   CASE\n    -&gt;     WHEN Gender = 'M'\n    -&gt;     THEN 4\n    -&gt;     ELSE 1\n    -&gt;   END;\n+--------+----------+\n| Gender | COUNT(*) |\n+--------+----------+\n| F      |        2 |\n+--------+----------+\n1 row in set (0.00 sec)\n\nmysql&gt;<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/09\/sql-case-having.jpg\"><img decoding=\"async\" width=\"715\" height=\"456\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/09\/sql-case-having.jpg\" alt=\"\" class=\"wp-image-104866\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/09\/sql-case-having.jpg 715w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/09\/sql-case-having-300x191.jpg 300w\" sizes=\"(max-width: 715px) 100vw, 715px\" \/><\/a><figcaption>SQL Case and Having Clause<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-4-summary\">4. Summary<\/h2>\n<p>In this example, we learned the following things: <\/p>\n<ol class=\"wp-block-list\">\n<li>The functionality of <a href=\"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-case\/\">SQL CASE<\/a> Statement. <\/li>\n<li>Usage of SQL CASE Statement in different ways. <\/li>\n<\/ol>\n<h2 class=\"wp-block-heading\" id=\"h-5-download-the-source-code\">5. Download the source code<\/h2>\n<p>You can download the scripts from here, and replicate them on your SQL command-line client or workbench. <\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/09\/sql-case.zip\"><strong>SQL CASE Statement Example<\/strong><\/a><\/div>\n<p><strong>Last updated on Feb. 24th, 2022<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This example will focus on the SQL Case Statement. In any programming language, you would know that the control statements are the most essential part of the programming language. Just like if-else in any of the programming languages, SQL also has the control statements. 1. About SQL CASE Statement There will be a list of &hellip;<\/p>\n","protected":false},"author":234,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[46656,1055],"class_list":["post-94523","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql","tag-case-statement","tag-sql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL CASE Statement Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"The CASE statement in SQL goes through every condition one by one, and returns only the value for the first true statement.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL CASE Statement Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"The CASE statement in SQL goes through every condition one by one, and returns only the value for the first true statement.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-16T08:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-24T09:45:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Simran Koul\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Simran Koul\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/\"},\"author\":{\"name\":\"Simran Koul\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5f017b27433db0a02e2ea1cedd4ec94c\"},\"headline\":\"SQL CASE Statement Example\",\"datePublished\":\"2020-09-16T08:00:00+00:00\",\"dateModified\":\"2022-02-24T09:45:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/\"},\"wordCount\":737,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"case statement\",\"sql\"],\"articleSection\":[\"sql\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/\",\"name\":\"SQL CASE Statement Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2020-09-16T08:00:00+00:00\",\"dateModified\":\"2022-02-24T09:45:42+00:00\",\"description\":\"The CASE statement in SQL goes through every condition one by one, and returns only the value for the first true statement.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"sql\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"SQL CASE Statement Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5f017b27433db0a02e2ea1cedd4ec94c\",\"name\":\"Simran Koul\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/Capture-1-96x96.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/Capture-1-96x96.png\",\"caption\":\"Simran Koul\"},\"description\":\"Simran has graduated as a Bachelor of Engineering in Computer Science from Chitkara University. She has undergone a 6-months long comprehensive industrial training at the reputed Centre for Development of Advanced Computing (C-DAC), where she worked on a project including the likes of Java, JSP, Servlets while the UI-UX through the pioneering HTML, CSS and JS. Her inquisitive nature and the seed of curiosity keeps her on the toes to find material to write about. Along with her interests in Software Development, she is an ardent reader and always ready-to-write writer.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/simran-koul\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL CASE Statement Example - Java Code Geeks","description":"The CASE statement in SQL goes through every condition one by one, and returns only the value for the first true statement.","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:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/","og_locale":"en_US","og_type":"article","og_title":"SQL CASE Statement Example - Java Code Geeks","og_description":"The CASE statement in SQL goes through every condition one by one, and returns only the value for the first true statement.","og_url":"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2020-09-16T08:00:00+00:00","article_modified_time":"2022-02-24T09:45:42+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Simran Koul","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Simran Koul","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/"},"author":{"name":"Simran Koul","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5f017b27433db0a02e2ea1cedd4ec94c"},"headline":"SQL CASE Statement Example","datePublished":"2020-09-16T08:00:00+00:00","dateModified":"2022-02-24T09:45:42+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/"},"wordCount":737,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["case statement","sql"],"articleSection":["sql"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/","url":"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/","name":"SQL CASE Statement Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2020-09-16T08:00:00+00:00","dateModified":"2022-02-24T09:45:42+00:00","description":"The CASE statement in SQL goes through every condition one by one, and returns only the value for the first true statement.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/sql-case-statement-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"sql","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/"},{"@type":"ListItem","position":5,"name":"SQL CASE Statement Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/5f017b27433db0a02e2ea1cedd4ec94c","name":"Simran Koul","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/Capture-1-96x96.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/Capture-1-96x96.png","caption":"Simran Koul"},"description":"Simran has graduated as a Bachelor of Engineering in Computer Science from Chitkara University. She has undergone a 6-months long comprehensive industrial training at the reputed Centre for Development of Advanced Computing (C-DAC), where she worked on a project including the likes of Java, JSP, Servlets while the UI-UX through the pioneering HTML, CSS and JS. Her inquisitive nature and the seed of curiosity keeps her on the toes to find material to write about. Along with her interests in Software Development, she is an ardent reader and always ready-to-write writer.","url":"https:\/\/examples.javacodegeeks.com\/author\/simran-koul\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/94523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/234"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=94523"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/94523\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=94523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=94523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=94523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}