{"id":12391,"date":"2020-02-23T12:17:17","date_gmt":"2020-02-23T20:17:17","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=12391"},"modified":"2023-12-01T02:29:49","modified_gmt":"2023-12-01T10:29:49","slug":"sql-case","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/sql-case\/","title":{"rendered":"SQL Case"},"content":{"rendered":"\n<p>When you\u2019re working with a database, you may want to run an <code>if\/then<\/code> operation in your query. For example, you may want to go through a list of employees and change their probation status if they have been working with you for over a year. Or you may want to go through a list of players on a leaderboard and mark them as a winner if they rank in the top three.<\/p>\n\n\n\n<p>In order to run these operations in <code>SQL<\/code>, you have to use the <code>CASE<\/code> statement. The <code>SQL CASE<\/code> statement allows you to run <code>if\/then<\/code> operations, similar to how you can run <code>if\/then<\/code> procedures in Microsoft Excel.<\/p>\n\n\n\n<p>In this guide, we\u2019re going to break down the basics of the <code>SQL CASE<\/code> statement, and discuss how you can use it in your queries. We\u2019ll also discuss how to use multiple <code>SQL CASE<\/code> statements, and explore how <code>CASE<\/code> can be used with aggregate functions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Query Refresher<\/h2>\n\n\n\n<p>To retrieve information from a database, you need to write a query. Queries almost always start with the <code>SELECT<\/code> statement, which is used to tell the database which columns should be returned by the query. Queries also usually include a <code>FROM<\/code> clause, which tells the database which table the operation will search.<\/p>\n\n\n\n<p>Here\u2019s the syntax for a query in <code>SQL<\/code>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>SELECT column_name FROM table_name WHERE conditions_are_met;<\/pre><\/div>\n\n\n\n<p>Let\u2019s use an example to illustrate this in action. Here is a query that will return the names of all employees in our <code>employees<\/code> table: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>SELECT name FROM employees;<\/pre><\/div>\n\n\n\n<p>Our query returns the result: <\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td>name<\/td><\/tr><tr><td>Luke<br>Mike<br>Hannah<br>Geoff<br>Alexis&nbsp;<br>Emma<br>Jonah<br>Adam<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>(8 rows)<\/p>\n\n\n\n<p>If we wanted to retrieve multiple columns, we could do so by separating their names with a column. Or if we wanted to gather information about every column, we could use the asterisk (<code>*<\/code>) operator, which represents all the columns in an <code>SQL<\/code> table.<\/p>\n\n\n\n<p>In addition, if we want to filter records based on a specific set of conditions, we can use the <code>WHERE<\/code> clause. Here\u2019s an example of a query that finds the names of all employees who are based in the Albany branch of a company:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>SELECT name FROM employees WHERE branch = 'Albany';<\/pre><\/div>\n\n\n\n<p>Here is the result of our query:<\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td>name<\/td><\/tr><tr><td>Emma<br>Jonah<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>(2 rows)<\/p>\n\n\n\n<p>These are all relatively simple queries. But what if we wanted to perform an <code>if\/then<\/code> operation when we\u2019re running a query? That\u2019s where the <code>SQL<\/code> <code>CASE<\/code> statement can be helpful.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SQL CASE<\/h2>\n\n\n\n<p>The <code>CASE<\/code> statement can be used in <code>SQL<\/code> to define <code>if\/then<\/code> logic in our code. For example, if we wanted to give every employee a raise who has worked with our business for five or more years, we may want to use the <code>CASE<\/code> statement.<\/p>\n\n\n\n<p>Here\u2019s the syntax for the <code>SQL CASE<\/code> statement:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>SELECT column1_name\n\tCASE WHEN column2_name = 'X' THEN 'Y'\n\t\tELSE NULL END AS column3_name\n\tFROM table_name;<\/pre><\/div>\n\n\n\n<p>There is a lot going on in this query, so let\u2019s use an example to illustrate how it works. Let\u2019s say that we want to give every employee with more than five <code>employee of the month<\/code> awards a $200 raise. Here\u2019s an <code>SQL<\/code> statement that could accomplish that goal:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>SELECT name,\n\tCASE WHEN employee_month_awards &gt; 5 THEN 200\n\t\tELSE NULL END AS pending_raise\n\tFROM employees;<\/pre><\/div>\n\n\n\n<p>Our query returns the following from our searched case expression:<\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td>name<\/td><td>pending_raise<\/td><\/tr><tr><td>Luke<\/td><td><br><\/td><\/tr><tr><td>Mike<\/td><td><br><\/td><\/tr><tr><td>Hannah<\/td><td><br><\/td><\/tr><tr><td>Geoff<\/td><td><br><\/td><\/tr><tr><td>Alexis<\/td><td><br><\/td><\/tr><tr><td>Emma<\/td><td>200<\/td><\/tr><tr><td>Jonah<\/td><td><br><\/td><\/tr><tr><td>Adam<\/td><td>200<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>(8 rows)<\/p>\n\n\n\n<p>Let\u2019s break this down. The <code>CASE<\/code> statement checks each record and evaluates whether the conditional statement, <code>employee month awards &gt; 5<\/code>, is true. If the conditional statement is true, the value <code>200<\/code> will be printed in the <code>pending_raise<\/code> column. Where the conditional statement is false, a null value remains.<\/p>\n\n\n\n<p>Finally, our query returns the list of employee names, as well as the pending raises of those employees.<\/p>\n\n\n\n<p>It\u2019s important to note that the <code>SQL CASE<\/code> statement does not add a new column to our table. Rather, it creates a column in our <code>SELECT<\/code> query <em>output<\/em>, so that we can see who is eligible for a raise.<\/p>\n\n\n\n<p>In addition, if we wanted everyone who was not eligible for a raise to be given a <code>0<\/code> pending raise, we could specify <code>0<\/code> instead of <code>NULL<\/code> in our <code>ELSE<\/code> statement. We could also use an <code>ORDER BY<\/code> clause to order our statement if we wanted to see our data in a specific order.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SQL CASE and Multiple Conditions<\/h2>\n\n\n\n<p>The <code>CASE<\/code> statement can be used multiple times in the same query. If we wanted to give every employee who has three or more awards a $50 raise, and everyone who has five or more awards a $200 raise, we could use the following statement:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>SELECT name,\n\tCASE WHEN employee_month_awards &gt; 5 THEN 200\n\t\tWHEN employee_month_awards &gt; 3 THEN 50\n\t\tELSE 0 END AS pending_raise\n\tFROM employees;<\/pre><\/div>\n\n\n\n<p>The output from our query is as follows:<\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td>name<\/td><td>pending_raise<\/td><\/tr><tr><td>Luke<\/td><td>50<\/td><\/tr><tr><td>Mike<\/td><td>0<\/td><\/tr><tr><td>Hannah<\/td><td>0<\/td><\/tr><tr><td>Geoff<\/td><td>0<\/td><\/tr><tr><td>Alexis<\/td><td>0<\/td><\/tr><tr><td>Emma<\/td><td>200<\/td><\/tr><tr><td>Jonah<\/td><td>50<\/td><\/tr><tr><td>Adam<\/td><td>200<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>(8 rows)<\/p>\n\n\n\n<p>In our example, the <code>CASE<\/code> statements will be evaluated in the order in which they are written.&nbsp;<\/p>\n\n\n\n<p>So, our query first checks for people who have more than five awards, and sets their pending raise to <code>200<\/code>. Then, our query checks for people who have more than three awards, and sets their pending raise to <code>50<\/code>. Finally, if an employee doesn\u2019t meet any of the criteria, their pending raise will be set to <code>0<\/code>.<\/p>\n\n\n\n<p>However, this code could be more efficient. Instead of writing statements in a certain order so that our program works, we should write statements that do not overlap. Here\u2019s an example of a query that works in the same way as above, but uses <code>AND<\/code> statements to check the number of awards an employee has earned:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>SELECT name,\n\tCASE WHEN employee_month_awards &gt;= 3 AND employee_month_awards &lt;= 5 THEN 50\n\t\tWHEN employee_month_awards &gt; 5 THEN 200\n\t\tELSE 0 END AS pending_raise\n\tFROM employees;<\/pre><\/div>\n\n\n\n<p>Our query returns the same as our above query. However, this one doesn\u2019t depend on the order of <code>CASE<\/code> statements, which means we are less likely to make a mistake with a misplaced statement.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SQL CASE and Aggregate Functions<\/h2>\n\n\n\n<p>You can also use <code>CASE<\/code> with an aggregate function. This can be useful if you only want to count rows that meet a certain condition. For example, if you want to find out how many employees have earned a bonus of $200, you could use <code>CASE<\/code> with an aggregate function.<\/p>\n\n\n\n<p>Here\u2019s the syntax for using <code>CASE<\/code> with an aggregate function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>SELECT column1_name\n\tCASE WHEN column2_name = 'X' THEN 'Y'\n\t\tELSE NULL END AS column3_name,\n\t\tCOUNT(1) AS count\n\tFROM table_name\nGROUP BY column3_name;<\/pre><\/div>\n\n\n\n<p>Let\u2019s use an example to illustrate how this works. Let\u2019s say that we want to find out how many employees are eligible for a bonus of $50 or over. We could use the following query to get this information: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>SELECT \n\tCASE WHEN employee_month_awards &gt;= 3 AND employee_month_awards &lt;= 5 THEN 50\n\t\tWHEN employee_month_awards &gt; 5 THEN 200\n\t\tELSE 0 END AS pending_raise,\n\t\tCOUNT(1) AS count\n\tFROM employees\nGROUP BY pending_raise;<\/pre><\/div>\n\n\n\n<p>Our query returns the following:<\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td>pending_raise<\/td><td>count<\/td><\/tr><tr><td>50<\/td><td>3<\/td><\/tr><tr><td>0<\/td><td>3<\/td><\/tr><tr><td>200<\/td><td>2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>As you can see, our query has returned a list of the pending raises earned by employees, as well as the number of each type of raise that employees are due. In this case, three employees are due a $50 raise, three employees are due no raise, and two employees are due a $200 raise.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In this tutorial, we have broken down the basics of the <code>SQL<\/code> server <code>CASE<\/code> statement and discussed how it can be used to implement <code>if\/then<\/code> logic in our queries. We also discussed how <code>CASE<\/code> can be used with multiple conditions and aggregate functions.<\/p>\n\n\n\n<p>As a reminder, every simple <code>CASE<\/code> expression should follow these rules:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>CASE<\/code> statement should be in the <code>SELECT<\/code> clause;<\/li>\n\n\n\n<li>The <code>CASE<\/code> statement should include <code>WHEN<\/code>, <code>THEN<\/code>, and <code>END<\/code> components;<\/li>\n\n\n\n<li>Multiple <code>WHEN<\/code> statements and <code>ELSE<\/code> clauses can be used optionally;<\/li>\n\n\n\n<li>Conditional statements, such as <code>AND<\/code> or <code>OR<\/code>, can be used in a <code>CASE<\/code> query between the <code>WHEN<\/code> and <code>THEN<\/code> clauses.<\/li>\n<\/ul>\n\n\n\n<p>Now you\u2019re equipped with the knowledge you need to use <code>CASE<\/code> statements like an <code>SQL<\/code> professional!<\/p>\n","protected":false},"excerpt":{"rendered":"When you\u2019re working with a database, you may want to run an if\/then operation in your query. For example, you may want to go through a list of employees and change their probation status if they have been working with you for over a year. Or you may want to go through a list of&hellip;","protected":false},"author":240,"featured_media":12392,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17284],"tags":[],"class_list":{"0":"post-12391","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-sql"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"SQL","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>SQL Case: an equivalation of if\/then operation in your query.<\/title>\n<meta name=\"description\" content=\"Learn about how SQL case works and how you can use it in a query in this Career Karma guide.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/sql-case\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Case\" \/>\n<meta property=\"og:description\" content=\"Learn about how SQL case works and how you can use it in a query in this Career Karma guide.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/sql-case\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-23T20:17:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T10:29:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-CASE.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"562\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\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:\/\/careerkarma.com\/blog\/sql-case\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-case\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"SQL Case\",\"datePublished\":\"2020-02-23T20:17:17+00:00\",\"dateModified\":\"2023-12-01T10:29:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-case\/\"},\"wordCount\":1122,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-case\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-CASE.jpg\",\"articleSection\":[\"SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/sql-case\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-case\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/sql-case\/\",\"name\":\"SQL Case: an equivalation of if\/then operation in your query.\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-case\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-case\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-CASE.jpg\",\"datePublished\":\"2020-02-23T20:17:17+00:00\",\"dateModified\":\"2023-12-01T10:29:49+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"Learn about how SQL case works and how you can use it in a query in this Career Karma guide.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-case\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/sql-case\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-case\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-CASE.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-CASE.jpg\",\"width\":1000,\"height\":562},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-case\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL\",\"item\":\"https:\/\/careerkarma.com\/blog\/sql\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL Case\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL Case: an equivalation of if\/then operation in your query.","description":"Learn about how SQL case works and how you can use it in a query in this Career Karma guide.","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:\/\/careerkarma.com\/blog\/sql-case\/","og_locale":"en_US","og_type":"article","og_title":"SQL Case","og_description":"Learn about how SQL case works and how you can use it in a query in this Career Karma guide.","og_url":"https:\/\/careerkarma.com\/blog\/sql-case\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-02-23T20:17:17+00:00","article_modified_time":"2023-12-01T10:29:49+00:00","og_image":[{"width":1000,"height":562,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-CASE.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/sql-case\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/sql-case\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"SQL Case","datePublished":"2020-02-23T20:17:17+00:00","dateModified":"2023-12-01T10:29:49+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/sql-case\/"},"wordCount":1122,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/sql-case\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-CASE.jpg","articleSection":["SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/sql-case\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/sql-case\/","url":"https:\/\/careerkarma.com\/blog\/sql-case\/","name":"SQL Case: an equivalation of if\/then operation in your query.","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/sql-case\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/sql-case\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-CASE.jpg","datePublished":"2020-02-23T20:17:17+00:00","dateModified":"2023-12-01T10:29:49+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"Learn about how SQL case works and how you can use it in a query in this Career Karma guide.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/sql-case\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/sql-case\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/sql-case\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-CASE.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-CASE.jpg","width":1000,"height":562},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/sql-case\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"SQL","item":"https:\/\/careerkarma.com\/blog\/sql\/"},{"@type":"ListItem","position":3,"name":"SQL Case"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=12391"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12391\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/12392"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=12391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=12391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=12391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}