{"id":2379,"date":"2013-05-14T22:26:00","date_gmt":"2013-05-15T06:26:00","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=2379"},"modified":"2020-04-11T02:02:20","modified_gmt":"2020-04-11T09:02:20","slug":"mysql-nullif","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/mysql-nullif\/","title":{"rendered":"MySQL NULLIF"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn about the <strong>MySQL NULLIF<\/strong> function and how to use it to prevent the division by zero error in a query.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to MySQL NULLIF function<\/h2>\n\n\n\n<p>The <code>NULLIF<\/code> function is one of the control flow functions that accepts 2 arguments. The <code>NULLIF<\/code> function returns <code>NULL<\/code> if the first argument is equal to the second argument, otherwise it returns the first argument.<\/p>\n\n\n\n<p>The syntax of the <code>NULLIF<\/code> function is as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">NULLIF(expression_1,expression_2);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>NULLIF<\/code> function returns <code>NULL<\/code> if <code>expression_1 = expression_2<\/code> is <code>true<\/code> , otherwise it returns <code>expression_1<\/code><\/p>\n\n\n\n<p>Notice that the <code>NULLIF<\/code> function is similar to the following expression that uses the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/mysql-case-function\/\">CASE expression<\/a>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">CASE WHEN expression_1 = expression_2\n   THEN NULL\nELSE\n   expression_1\n<span class=\"hljs-keyword\">END<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Note that you should not confuse the <code>NULLIF<\/code> function a similar function called <a title=\"MySQL IFNULL function\" href=\"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/mysql-ifnull\/\">IFNULL function<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL NULLIF examples<\/h2>\n\n\n\n<p>Let&#8217;s take a look at some examples of using the <code>NULLIF<\/code> function to understand how it works.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">NULLIF<\/span>(<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">1<\/span>); <span class=\"hljs-comment\">-- return NULL<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-nullif\/#1\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">NULLIF<\/span>(<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">2<\/span>); <span class=\"hljs-comment\">-- return 1<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-nullif\/#2\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">NULLIF<\/span>(<span class=\"hljs-string\">'MySQL NULLIF'<\/span>,<span class=\"hljs-string\">'MySQL NULLIF'<\/span>); <span class=\"hljs-comment\">-- return NULL<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-nullif\/#3\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">NULLIF<\/span>(<span class=\"hljs-string\">'MySQL NULLIF'<\/span>,<span class=\"hljs-string\">'MySQL IFNULL'<\/span>); <span class=\"hljs-comment\">-- return MySQL NULLIF<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-nullif\/#4\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">NULLIF<\/span>(<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-literal\">NULL<\/span>); <span class=\"hljs-comment\">-- return 1 because 1 &lt;=&gt; NULL<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-nullif\/#5\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">NULLIF<\/span>(<span class=\"hljs-literal\">NULL<\/span>,<span class=\"hljs-number\">1<\/span>); <span class=\"hljs-comment\">-- return NULL the first argument<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-nullif\/#6\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<p>How the statements work.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><span style=\"line-height: 13px;\"> <code>NULIF(1,1)<\/code> returns <code>NULL<\/code> because 1 is equal 1.<\/span><\/li><li><code>NULLIF(1,2)<\/code> returns 1, which is the first argument, because 1 is not equal 2.<\/li><li><code>NULLIF('MySQL NULLIF','MySQL NULLIF')<\/code> returns <code>NULL<\/code> because two arguments are the same string<\/li><li><code>NULLIF('MySQL NULLIF','MySQL NULLIF')<\/code> returns <code>MySQL NULLIF<\/code> because two strings are not equal.<\/li><li><code>NULLIF(1,NULL)<\/code> returns 1 because 1 is not equal to <code>NULL<\/code><\/li><li><code>NULLIF(NULL,1)<\/code> return the first argument i.e., <code>NULL<\/code> , because <code>NULL<\/code> is not equal to 1.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Using NULLIF function to prevent division by zero error<\/h2>\n\n\n\n<p>We often use the <code>NULLIF<\/code> function to prevent the division by zero error in a query. If the MySQL server has <code>ERROR_FOR_DIVISION_BY_ZERO<\/code> mode enabled, it will issue an error when a division by zero occurred.<\/p>\n\n\n\n<p>See the following statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-number\">1<\/span>\/<span class=\"hljs-number\">0<\/span>; <span class=\"hljs-comment\">-- cause error<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-nullif\/#7\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<p>In this case, you can use the <code>NULLIF<\/code> function to prevent the division by zero as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-number\">1<\/span>\/<span class=\"hljs-keyword\">NULLIF<\/span>(<span class=\"hljs-number\">0<\/span>,<span class=\"hljs-number\">0<\/span>); <span class=\"hljs-comment\">-- return NULL<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-nullif\/#8\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<p>Because zero is equal to zero, the expression <code>NULLIF(0,0)<\/code> returns NULL. As the result, the statement returns NULL.<\/p>\n\n\n\n<p>Let&#8217;s take a look at the <code>orders<\/code> table in the <a href=\"https:\/\/www.mysqltutorial.org\/getting-started-with-mysql\/mysql-sample-database\/\">sample database<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"181\" height=\"194\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2009\/12\/orders_table.png\" alt=\"orders table\" class=\"wp-image-719\"\/><\/figure>\n\n\n\n<p>First, to get all orders created in June 2003, you use the following query:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n    orderNumber, orderdate, requiredDate, shippedDate, <span class=\"hljs-keyword\">status<\/span>\n<span class=\"hljs-keyword\">FROM<\/span>\n    orders\n<span class=\"hljs-keyword\">WHERE<\/span>\n    orderDate <span class=\"hljs-keyword\">BETWEEN<\/span> <span class=\"hljs-string\">'2003-06-01'<\/span> <span class=\"hljs-keyword\">AND<\/span> <span class=\"hljs-string\">'2003-06-30'<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-nullif\/#9\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"390\" height=\"172\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/05\/MySQL-NULLIF-example.jpg\" alt=\"MySQL NULLIF example\" class=\"wp-image-4604\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/05\/MySQL-NULLIF-example.jpg 390w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/05\/MySQL-NULLIF-example-300x132.jpg 300w\" sizes=\"auto, (max-width: 390px) 100vw, 390px\" \/><\/figure>\n\n\n\n<p>Second, calculate the number of shipped orders \/ the number of cancelled orders in June 2003, you use the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-aggregate-functions\/mysql-sum\/\">SUM<\/a> and <a href=\"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/mysql-if-function\/\">IF<\/a> functions.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">SUM<\/span>(<span class=\"hljs-keyword\">IF<\/span>(<span class=\"hljs-keyword\">status<\/span> = <span class=\"hljs-string\">'Shipped'<\/span>,<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">0<\/span>)) \/ \n       <span class=\"hljs-keyword\">SUM<\/span>(<span class=\"hljs-keyword\">IF<\/span>(<span class=\"hljs-keyword\">status<\/span> = <span class=\"hljs-string\">'Cancelled'<\/span>,<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">0<\/span>))\n<span class=\"hljs-keyword\">FROM<\/span> orders\n<span class=\"hljs-keyword\">WHERE<\/span> orderDate <span class=\"hljs-keyword\">BETWEEN<\/span> <span class=\"hljs-string\">'2003-06-01'<\/span> <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-string\">'2003-06-30'<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-nullif\/#10\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<p>MySQL issues an error because in June 2003 there was no cancelled order created. It means that expression <code>SUM(IF(status = 'Cancelled',1,0))<\/code> returns zero.<\/p>\n\n\n\n<p>Third, to prevent the division by zero error, you use the <code>NULLIF<\/code> function as the following query:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n    <span class=\"hljs-keyword\">SUM<\/span>(<span class=\"hljs-keyword\">IF<\/span>(<span class=\"hljs-keyword\">status<\/span> = <span class=\"hljs-string\">'Shipped'<\/span>, <span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">0<\/span>)) \/ \n    <span class=\"hljs-keyword\">NULLIF<\/span>(<span class=\"hljs-keyword\">SUM<\/span>(<span class=\"hljs-keyword\">IF<\/span>(<span class=\"hljs-keyword\">status<\/span> = <span class=\"hljs-string\">'Cancelled'<\/span>, <span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">0<\/span>)), <span class=\"hljs-number\">0<\/span>)\n<span class=\"hljs-keyword\">FROM<\/span>\n    orders\n<span class=\"hljs-keyword\">WHERE<\/span>\n    orderDate <span class=\"hljs-keyword\">BETWEEN<\/span> <span class=\"hljs-string\">'2003-06-01'<\/span> <span class=\"hljs-keyword\">AND<\/span> <span class=\"hljs-string\">'2003-06-30'<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-nullif\/#11\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"277\" height=\"98\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/05\/MySQL-NULLIF-function-example.jpg\" alt=\"MySQL NULLIF function example\" class=\"wp-image-4605\" title=\"MySQL NULLIF function example\"\/><\/figure>\n\n\n\n<p>Because there was no cancelled order created in June 2003, the <code>SUM(IF(status = 'Cancelled',1,0) <\/code>expression returns zero, which also makes the <code>NULLIF(SUM(IF(status = 'Cancelled',1,0),0)<\/code> expression returns a <code>NULL<\/code> value.<\/p>\n\n\n\n<p>In this tutorial, we have introduced you to <code>NULLIF<\/code> function, which is very handy in some cases such as preventing division by zero error in queries.<\/p>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful? <\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"2379\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/mysql-nullif\/\"\n\t\t\t\tdata-post-title=\"MySQL NULLIF\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"2379\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/mysql-nullif\/\"\n\t\t\t\tdata-post-title=\"MySQL NULLIF\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial introduces you to the MySQL NULLIF function and shows you how to use the NULLIF function to prevent the division by zero error.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":7030,"menu_order":3,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-2379","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MySQL NULLIF - Prevents Division By Zero Error<\/title>\n<meta name=\"description\" content=\"This tutorial introduces you to the MySQL NULLIF function and shows you how to use the NULLIF function to prevent the division by zero error.\" \/>\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-nullif\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL NULLIF - Prevents Division By Zero Error\" \/>\n<meta property=\"og:description\" content=\"This tutorial introduces you to the MySQL NULLIF function and shows you how to use the NULLIF function to prevent the division by zero error.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-nullif\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-11T09:02:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2009\/12\/orders_table.png\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-nullif\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-nullif\\\/\",\"name\":\"MySQL NULLIF - Prevents Division By Zero Error\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-nullif\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-nullif\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2009\\\/12\\\/orders_table.png\",\"datePublished\":\"2013-05-15T06:26:00+00:00\",\"dateModified\":\"2020-04-11T09:02:20+00:00\",\"description\":\"This tutorial introduces you to the MySQL NULLIF function and shows you how to use the NULLIF function to prevent the division by zero error.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-nullif\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-nullif\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-nullif\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2009\\\/12\\\/orders_table.png\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2009\\\/12\\\/orders_table.png\",\"width\":181,\"height\":194,\"caption\":\"orders table\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-nullif\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL Control Flow Functions and Expressions\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-control-flow-functions\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MySQL NULLIF\"}]},{\"@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 NULLIF - Prevents Division By Zero Error","description":"This tutorial introduces you to the MySQL NULLIF function and shows you how to use the NULLIF function to prevent the division by zero error.","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-nullif\/","og_locale":"en_US","og_type":"article","og_title":"MySQL NULLIF - Prevents Division By Zero Error","og_description":"This tutorial introduces you to the MySQL NULLIF function and shows you how to use the NULLIF function to prevent the division by zero error.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-nullif\/","og_site_name":"MySQL Tutorial","article_modified_time":"2020-04-11T09:02:20+00:00","og_image":[{"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2009\/12\/orders_table.png","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-nullif\/","url":"https:\/\/www.mysqltutorial.org\/mysql-nullif\/","name":"MySQL NULLIF - Prevents Division By Zero Error","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-nullif\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-nullif\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2009\/12\/orders_table.png","datePublished":"2013-05-15T06:26:00+00:00","dateModified":"2020-04-11T09:02:20+00:00","description":"This tutorial introduces you to the MySQL NULLIF function and shows you how to use the NULLIF function to prevent the division by zero error.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-nullif\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-nullif\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-nullif\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2009\/12\/orders_table.png","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2009\/12\/orders_table.png","width":181,"height":194,"caption":"orders table"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-nullif\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL Control Flow Functions and Expressions","item":"https:\/\/www.mysqltutorial.org\/mysql-control-flow-functions\/"},{"@type":"ListItem","position":3,"name":"MySQL NULLIF"}]},{"@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\/2379","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=2379"}],"version-history":[{"count":0,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/2379\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/7030"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=2379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}