{"id":875,"date":"2016-07-15T02:04:34","date_gmt":"2016-07-15T02:04:34","guid":{"rendered":"https:\/\/sqltutorial.org\/?page_id=875"},"modified":"2025-02-08T01:30:33","modified_gmt":"2025-02-08T08:30:33","slug":"sql-coalesce","status":"publish","type":"page","link":"https:\/\/www.sqltutorial.org\/sql-coalesce\/","title":{"rendered":"SQL COALESCE Function"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn how to use the SQL <code>COALESCE()<\/code> function to handle <code>NULL<\/code> effectively.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-the-sql-coalesce-function'>Introduction to the SQL COALESCE function <a href=\"#introduction-to-the-sql-coalesce-function\" class=\"anchor\" id=\"introduction-to-the-sql-coalesce-function\" title=\"Anchor for Introduction to the SQL COALESCE function\">#<\/a><\/h2>\n\n\n\n<p>In SQL, the <code>COALESCE()<\/code> function takes one or more arguments and returns the first non-NULL argument.<\/p>\n\n\n\n<p>Here&#8217;s the syntax of the <code>COALESCE<\/code> function:<\/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\">COALESCE(argument1, argument2,...);<\/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>COALESCE<\/code> function evaluates its arguments from left to right and returns the first non-NULL argument.<\/p>\n\n\n\n<p>The <code>COALESCE<\/code> function will return <code>NULL<\/code> in case all input arguments are <code>NULL<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='basic-sql-coalesce-function-examples'>Basic SQL COALESCE function examples <a href=\"#basic-sql-coalesce-function-examples\" class=\"anchor\" id=\"basic-sql-coalesce-function-examples\" title=\"Anchor for Basic SQL COALESCE function examples\">#<\/a><\/h2>\n\n\n\n<p>The following example shows how to use the <code>COALESCE<\/code> function with numbers 1, 2, and 3:<\/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\"><span class=\"hljs-keyword\">SELECT<\/span>\n  <span class=\"hljs-keyword\">COALESCE<\/span>(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">2<\/span>, <span class=\"hljs-number\">3<\/span>) <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">result<\/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><a href=\"https:\/\/www.sqltutorial.org\/playground\/?q=U0VMRUNUIENPQUxFU0NFKDEsIDIsIDMpIEFTIHJlc3VsdDs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/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\"> result\n<span class=\"hljs-comment\">--------<\/span>\n      1<\/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>The result is 1 because it is the first non-NULL argument.<\/p>\n\n\n\n<p>The following statement returns the string <code>SQL<\/code> because it is the first non-NULL argument.<\/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>\n  <span class=\"hljs-keyword\">COALESCE<\/span>(<span class=\"hljs-literal\">NULL<\/span>, <span class=\"hljs-string\">'SQL'<\/span>, <span class=\"hljs-string\">'Tutorial'<\/span>) <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">result<\/span>;<\/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 href=\"https:\/\/www.sqltutorial.org\/playground\/?q=U0VMRUNUIENPQUxFU0NFKE5VTEwsICdTUUwnLCAnVHV0b3JpYWwnKSBBUyByZXN1bHQ7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/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\"> result\n<span class=\"hljs-comment\">--------<\/span>\n SQL<\/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<h2 class=\"wp-block-heading\" id='short-circuit-evaluation'>Short-circuit evaluation <a href=\"#short-circuit-evaluation\" class=\"anchor\" id=\"short-circuit-evaluation\" title=\"Anchor for Short-circuit evaluation\">#<\/a><\/h2>\n\n\n\n<p>If you divide by zero, you&#8217;ll encounter an error:<\/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-number\">1<\/span>\/<span class=\"hljs-number\">0<\/span>;<\/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 href=\"https:\/\/www.sqltutorial.org\/playground\/?q=U0VMRUNUIDEvMDs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/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\">ERROR:  division by zero<\/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>But the following statement returns one instead of an error:<\/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>\n  <span class=\"hljs-keyword\">COALESCE<\/span>(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span> \/ <span class=\"hljs-number\">0<\/span>) <span class=\"hljs-keyword\">result<\/span>;<\/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 href=\"https:\/\/www.sqltutorial.org\/playground\/?q=U0VMRUNUIENPQUxFU0NFKDEsIDEgLyAwKSByZXN1bHQ7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/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\"> result\n<span class=\"hljs-comment\">--------<\/span>\n      1<\/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>The reason is that the <code>COALESCE<\/code> function uses short-circuit evaluation. It means that the <code>COALESCE<\/code> function does not evaluate the remaining arguments after it encounters the first non-NULL arguments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='using-sql-coalesce-function-to-substitute-null'>Using SQL COALESCE function to substitute NULL <a href=\"#using-sql-coalesce-function-to-substitute-null\" class=\"anchor\" id=\"using-sql-coalesce-function-to-substitute-null\" title=\"Anchor for Using SQL COALESCE function to substitute NULL\">#<\/a><\/h2>\n\n\n\n<p>First, <a href=\"https:\/\/www.sqltutorial.org\/sql-create-table\/\">create a new table<\/a> called <code>bonuses<\/code> to store employee bonuses:<\/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\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> bonuses (\n  employee_id <span class=\"hljs-built_in\">INT<\/span> PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n  amount <span class=\"hljs-built_in\">DECIMAL<\/span>(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">2<\/span>) <span class=\"hljs-literal\">NULL<\/span>\n);<\/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 href=\"https:\/\/www.sqltutorial.org\/playground\/?q=Q1JFQVRFIFRBQkxFIGJvbnVzZXMgKCBlbXBsb3llZV9pZCBJTlQgUFJJTUFSWSBLRVksIGFtb3VudCBERUNJTUFMKDEwLCAyKSBOVUxMICk7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Some employees may have bonuses so that the amount column can be NULL.<\/p>\n\n\n\n<p>Second, <a href=\"https:\/\/www.sqltutorial.org\/sql-insert\/\">insert some rows<\/a> into the <code>bonuses<\/code> table:<\/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\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span>\n  bonuses (employee_id, amount)\n<span class=\"hljs-keyword\">VALUES<\/span>\n  (<span class=\"hljs-number\">101<\/span>, <span class=\"hljs-number\">1000.00<\/span>),\n  (<span class=\"hljs-number\">102<\/span>, <span class=\"hljs-literal\">NULL<\/span>),\n  (<span class=\"hljs-number\">103<\/span>, <span class=\"hljs-number\">1500.00<\/span>),\n  (<span class=\"hljs-number\">104<\/span>, <span class=\"hljs-literal\">NULL<\/span>),\n  (<span class=\"hljs-number\">105<\/span>, <span class=\"hljs-number\">2000.00<\/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 href=\"https:\/\/www.sqltutorial.org\/playground\/?q=SU5TRVJUIElOVE8gYm9udXNlcyAoZW1wbG95ZWVfaWQsIGFtb3VudCkgVkFMVUVTICgxMDEsIDEwMDAuMDApLCAoMTAyLCBOVUxMKSwgKDEwMywgMTUwMC4wMCksICgxMDQsIE5VTEwpLCAoMTA1LCAyMDAwLjAwKTs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Third, use the <code>COALESCE<\/code> function to replace <code>NULL<\/code> with zero when calculating the total compensation that includes both salary and bonus:<\/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>\n  e.first_name,\n  e.last_name,\n  e.salary,\n  e.salary + <span class=\"hljs-keyword\">COALESCE<\/span>(b.amount, <span class=\"hljs-number\">0<\/span>) <span class=\"hljs-keyword\">AS<\/span> total_compensation\n<span class=\"hljs-keyword\">FROM<\/span>\n  employees e\n  <span class=\"hljs-keyword\">LEFT<\/span> <span class=\"hljs-keyword\">JOIN<\/span> bonuses b <span class=\"hljs-keyword\">ON<\/span> e.employee_id = b.employee_id;<\/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 href=\"https:\/\/www.sqltutorial.org\/playground\/?q=U0VMRUNUIGUuZmlyc3RfbmFtZSwgZS5sYXN0X25hbWUsIGUuc2FsYXJ5LCBlLnNhbGFyeSArIENPQUxFU0NFKGIuYW1vdW50LCAwKSBBUyB0b3RhbF9jb21wZW5zYXRpb24gRlJPTSBlbXBsb3llZXMgZSBMRUZUIEpPSU4gYm9udXNlcyBiIE9OIGUuZW1wbG95ZWVfaWQgPSBiLmVtcGxveWVlX2lkOw%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/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\"> first_name  |  last_name  |  salary  | total_compensation\n<span class=\"hljs-comment\">-------------+-------------+----------+--------------------<\/span>\n Neena       | Kochhar     | 17000.00 |           18000.00\n Lex         | De Haan     | 17000.00 |           17000.00\n Alexander   | Hunold      |  9000.00 |           10500.00\n Bruce       | Ernst       |  6000.00 |            6000.00\n...<\/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<h2 class=\"wp-block-heading\" id='sql-coalesce-and-case-expression'>SQL COALESCE and CASE expression <a href=\"#sql-coalesce-and-case-expression\" class=\"anchor\" id=\"sql-coalesce-and-case-expression\" title=\"Anchor for SQL COALESCE and CASE expression\">#<\/a><\/h2>\n\n\n\n<p>The <code>COALESCE<\/code> function is functionally equivalent to the following <code><a href=\"https:\/\/www.sqltutorial.org\/sql-case\/\">CASE<\/a><\/code> expression:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">CASE\n  WHEN (argument1 IS NOT NULL) THEN argument1\n  WHEN (argument2 IS NOT NULL) THEN argument2\n  ELSE argument3\n<span class=\"hljs-keyword\">END<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><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 following <a href=\"https:\/\/www.sqltutorial.org\/sql-select\/\">query<\/a> uses the <code>CASE<\/code> expression instead of the <code>COALESCE<\/code> function:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" 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  e.first_name,\n  e.last_name,\n  e.salary,\n  e.salary + <span class=\"hljs-keyword\">CASE<\/span>\n    <span class=\"hljs-keyword\">WHEN<\/span> b.amount <span class=\"hljs-keyword\">IS<\/span> <span class=\"hljs-literal\">NULL<\/span> <span class=\"hljs-keyword\">THEN<\/span> <span class=\"hljs-number\">0<\/span>\n    <span class=\"hljs-keyword\">ELSE<\/span> b.amount\n  <span class=\"hljs-keyword\">END<\/span> <span class=\"hljs-keyword\">AS<\/span> total_compensation\n<span class=\"hljs-keyword\">FROM<\/span>\n  employees e\n  <span class=\"hljs-keyword\">LEFT<\/span> <span class=\"hljs-keyword\">JOIN<\/span> bonuses b <span class=\"hljs-keyword\">ON<\/span> e.employee_id = b.employee_id;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><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 href=\"https:\/\/www.sqltutorial.org\/playground\/?q=U0VMRUNUIGUuZmlyc3RfbmFtZSwgZS5sYXN0X25hbWUsIGUuc2FsYXJ5LCBlLnNhbGFyeSArIENBU0UgV0hFTiBiLmFtb3VudCBJUyBOVUxMIFRIRU4gMCBFTFNFIGIuYW1vdW50IEVORCBBUyB0b3RhbF9jb21wZW5zYXRpb24gRlJPTSBlbXBsb3llZXMgZSBMRUZUIEpPSU4gYm9udXNlcyBiIE9OIGUuZW1wbG95ZWVfaWQgPSBiLmVtcGxveWVlX2lkOw%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"> first_name  |  last_name  |  salary  | total_compensation\n<span class=\"hljs-comment\">-------------+-------------+----------+--------------------<\/span>\n Neena       | Kochhar     | 17000.00 |           18000.00\n Lex         | De Haan     | 17000.00 |           17000.00\n Alexander   | Hunold      |  9000.00 |           10500.00\n Bruce       | Ernst       |  6000.00 |            6000.00\n...<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><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<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the SQL <code>COALESCE<\/code> function to return the first non-NULL argument from a list of arguments.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='quiz'>Quiz <a href=\"#quiz\" class=\"anchor\" id=\"quiz\" title=\"Anchor for Quiz\">#<\/a><\/h2>\n\n\n\n<iframe loading=\"lazy\"\n  name=\"quiz\"\n  src=\"\/quiz\/?quiz=coalesce\"\n  height=\"700\"\n  width=\"600\"\n  class=\"iframe\"\n><\/iframe>\n\n\n\n\n\n<h2 class=\"wp-block-heading\" id='databases'>Databases <a href=\"#databases\" class=\"anchor\" id=\"databases\" title=\"Anchor for Databases\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-coalesce\/\" target=\"_blank\" rel=\"noreferrer noopener\">PostgreSQL COALESCE Function<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.oracletutorial.com\/oracle-comparison-functions\/oracle-coalesce\/\" target=\"_blank\" rel=\"noreferrer noopener\">Oracle COALESCE Function<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-coalesce\/\" target=\"_blank\" rel=\"noreferrer noopener\">SQL Server COALESCE Function<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mysqltutorial.org\/mysql-comparison-functions\/mysql-coalesce\/\" target=\"_blank\" rel=\"noreferrer noopener\">MySQL COALESCE Function<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-functions\/sqlite-coalesce\/\" target=\"_blank\" rel=\"noreferrer noopener\">SQLite COALESCE Function<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.db2tutorial.com\/db2-basics\/db2-coalesce\/\" target=\"_blank\" rel=\"noreferrer noopener\">Db2 COALESCE Function<\/a><\/li>\n<\/ul>\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=\"875\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqltutorial.org\/sql-coalesce\/\"\n\t\t\t\tdata-post-title=\"SQL COALESCE Function\"\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=\"875\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqltutorial.org\/sql-coalesce\/\"\n\t\t\t\tdata-post-title=\"SQL COALESCE Function\"\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>In this tutorial, you&#8217;ll learn how to use the SQL COALESCE() function to query and calculate values and NULL effectively.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":50,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-875","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL COALESCE Function<\/title>\n<meta name=\"description\" content=\"In this tutorial, you&#039;ll learn how to use the SQL COALESCE() function to query and calculate values and NULL effectively.\" \/>\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.sqltutorial.org\/sql-coalesce\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL COALESCE Function\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you&#039;ll learn how to use the SQL COALESCE() function to query and calculate values and NULL effectively.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqltutorial.org\/sql-coalesce\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-08T08:30:33+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-coalesce\/\",\"url\":\"https:\/\/www.sqltutorial.org\/sql-coalesce\/\",\"name\":\"SQL COALESCE Function\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqltutorial.org\/#website\"},\"datePublished\":\"2016-07-15T02:04:34+00:00\",\"dateModified\":\"2025-02-08T08:30:33+00:00\",\"description\":\"In this tutorial, you'll learn how to use the SQL COALESCE() function to query and calculate values and NULL effectively.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-coalesce\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqltutorial.org\/sql-coalesce\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-coalesce\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqltutorial.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL COALESCE Function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqltutorial.org\/#website\",\"url\":\"https:\/\/www.sqltutorial.org\/\",\"name\":\"SQL Tutorial\",\"description\":\"An Interactive SQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqltutorial.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":"SQL COALESCE Function","description":"In this tutorial, you'll learn how to use the SQL COALESCE() function to query and calculate values and NULL effectively.","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.sqltutorial.org\/sql-coalesce\/","og_locale":"en_US","og_type":"article","og_title":"SQL COALESCE Function","og_description":"In this tutorial, you'll learn how to use the SQL COALESCE() function to query and calculate values and NULL effectively.","og_url":"https:\/\/www.sqltutorial.org\/sql-coalesce\/","og_site_name":"SQL Tutorial","article_modified_time":"2025-02-08T08:30:33+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqltutorial.org\/sql-coalesce\/","url":"https:\/\/www.sqltutorial.org\/sql-coalesce\/","name":"SQL COALESCE Function","isPartOf":{"@id":"https:\/\/www.sqltutorial.org\/#website"},"datePublished":"2016-07-15T02:04:34+00:00","dateModified":"2025-02-08T08:30:33+00:00","description":"In this tutorial, you'll learn how to use the SQL COALESCE() function to query and calculate values and NULL effectively.","breadcrumb":{"@id":"https:\/\/www.sqltutorial.org\/sql-coalesce\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqltutorial.org\/sql-coalesce\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqltutorial.org\/sql-coalesce\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"SQL COALESCE Function"}]},{"@type":"WebSite","@id":"https:\/\/www.sqltutorial.org\/#website","url":"https:\/\/www.sqltutorial.org\/","name":"SQL Tutorial","description":"An Interactive SQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages\/875","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/comments?post=875"}],"version-history":[{"count":0,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages\/875\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/media?parent=875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}