{"id":121,"date":"2024-11-19T11:36:07","date_gmt":"2024-11-19T04:36:07","guid":{"rendered":"https:\/\/www.pgtutorial.com\/?page_id=121"},"modified":"2025-01-01T16:24:40","modified_gmt":"2025-01-01T09:24:40","slug":"postgresql-where","status":"publish","type":"page","link":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-where\/","title":{"rendered":"PostgreSQL WHERE: Filtering Rows"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the PostgreSQL <code>WHERE<\/code> clause to filter rows in a table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='postgresql-where-clause'>PostgreSQL WHERE clause <a href=\"#postgresql-where-clause\" class=\"anchor\" id=\"postgresql-where-clause\" title=\"Anchor for PostgreSQL WHERE clause\">#<\/a><\/h2>\n\n\n\n<p>The <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-select\/\">SELECT FROM<\/a> statement retrieves data from one or more columns of <em>all rows<\/em> of a table. In practice, you often need to select rows that meet a condition.<\/p>\n\n\n\n<p>To filter rows from a table based on a condition, you use the <code>WHERE<\/code> clause in the <code>SELECT<\/code> statement:<\/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\"><span class=\"hljs-keyword\">SELECT<\/span> column1, column2, ...\n<span class=\"hljs-keyword\">FROM<\/span> table_name\n<span class=\"hljs-keyword\">WHERE<\/span> condition;<\/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>When executing the statement, PostgreSQL evaluates the <code>FROM<\/code> clause first, then the <code>WHERE<\/code> clause, and finally the <code>SELECT<\/code> clause:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, retrieve each row in the <code>table_name<\/code> by running the <code>FROM<\/code> clause.<\/li>\n\n\n\n<li>Second, evaluate the <code>condition<\/code> in the <code>WHERE<\/code> clause and include the row in the result set if the <code>condition<\/code> is true.<\/li>\n\n\n\n<li>Third, select the columns specified in the <code>SELECT<\/code> clause from the selected rows.<\/li>\n<\/ul>\n\n\n\n<p>If no rows from the <code>table_name<\/code> meet the <code>condition<\/code>, the <code>SELECT<\/code> statement returns an empty set, which contains no rows.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='postgresql-where-clause-example'>PostgreSQL WHERE clause example <a href=\"#postgresql-where-clause-example\" class=\"anchor\" id=\"postgresql-where-clause-example\" title=\"Anchor for PostgreSQL WHERE clause example\">#<\/a><\/h2>\n\n\n\n<p>Suppose we have the <code>inventories<\/code> table as follows:<\/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\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> inventories (\n  <span class=\"hljs-keyword\">name<\/span> <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">255<\/span>),\n  brand <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">50<\/span>),\n  quantity <span class=\"hljs-built_in\">INT<\/span>,\n  price <span class=\"hljs-built_in\">DECIMAL<\/span>(<span class=\"hljs-number\">19<\/span>, <span class=\"hljs-number\">2<\/span>)\n);\n\n\n<span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> inventories (<span class=\"hljs-keyword\">name<\/span>, brand, quantity, price)\n<span class=\"hljs-keyword\">VALUES<\/span> (<span class=\"hljs-string\">'iPhone 14 Pro'<\/span>, <span class=\"hljs-string\">'Apple'<\/span>, <span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">999.99<\/span>),\n       (<span class=\"hljs-string\">'Galaxy S23 Ultra'<\/span>, <span class=\"hljs-string\">'Samsung'<\/span>, <span class=\"hljs-number\">15<\/span>, <span class=\"hljs-number\">1199.99<\/span>),\n       (<span class=\"hljs-string\">'Pixel 7 Pro'<\/span>, <span class=\"hljs-string\">'Google'<\/span>, <span class=\"hljs-number\">8<\/span>, <span class=\"hljs-number\">899.99<\/span>),\n       (<span class=\"hljs-string\">'Xperia 1 IV'<\/span>, <span class=\"hljs-string\">'Sony'<\/span>, <span class=\"hljs-number\">7<\/span>, <span class=\"hljs-number\">1299.99<\/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>The following statement uses the <code>WHERE<\/code> clause to retrieve the products with a quantity greater than 9:<\/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\">name<\/span>, quantity\n<span class=\"hljs-keyword\">FROM<\/span> inventories\n<span class=\"hljs-keyword\">WHERE<\/span> quantity &gt; <span class=\"hljs-number\">9<\/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 href=\"https:\/\/www.pgtutorial.com\/playground\/?db=where&amp;q=U0VMRUNUIG5hbWUsIHF1YW50aXR5IEZST00gaW52ZW50b3JpZXMgV0hFUkUgcXVhbnRpdHkgPiA5Ow\" 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-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">       name       | quantity\n<span class=\"hljs-comment\">------------------+----------<\/span>\n iPhone 14 Pro    |       10\n Galaxy S23 Ultra |       15<\/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>How it works.<\/p>\n\n\n\n<p>First, the <code>FROM<\/code> clause selects all rows from the <code>inventories<\/code> table:<\/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\">       name       |  brand  | quantity |  price\n<span class=\"hljs-comment\">------------------+---------+----------+---------<\/span>\n iPhone 14 Pro    | Apple   |       10 |  999.99\n Galaxy S23 Ultra | Samsung |       15 | 1199.99\n Pixel 7 Pro      | Google  |        8 |  899.99\n Xperia 1 IV      | Sony    |        7 | 1299.99<\/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>Second, the <code>WHERE<\/code> clause evaluates each row in the <code>inventories<\/code> table, checks if the <code>quantity<\/code> is greater than <code>10<\/code>, and includes the rows in the intermediate result set:<\/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\">       name       |  brand  | quantity |  price\n<span class=\"hljs-comment\">------------------+---------+----------+---------<\/span>\n iPhone 14 Pro    | Apple   |       10 |  999.99\n Galaxy S23 Ultra | Samsung |       15 | 1199.99<\/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>It returns two rows with quantity 10 and 15.<\/p>\n\n\n\n<p>Third, the <code>SELECT<\/code> clause retrieves data from the <code>name<\/code> and <code>quantity<\/code> columns:<\/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\">       name       | quantity\n<span class=\"hljs-comment\">------------------+----------<\/span>\n iPhone 14 Pro    |       10\n Galaxy S23 Ultra |       15<\/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<h2 class=\"wp-block-heading\" id='comparison-operators'>Comparison operators <a href=\"#comparison-operators\" class=\"anchor\" id=\"comparison-operators\" title=\"Anchor for Comparison operators\">#<\/a><\/h2>\n\n\n\n<p>Besides the greater than operator &gt;, you can utilize other comparison operators inside the WHERE clause:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Operator<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td>=<\/td><td>Equal to<\/td><\/tr><tr><td>!= (&lt;&gt;)<\/td><td>Not Equal To<\/td><\/tr><tr><td>&gt;<\/td><td>Greater than<\/td><\/tr><tr><td>&gt;=<\/td><td>Greater than or equal to<\/td><\/tr><tr><td>&lt;<\/td><td>Less than<\/td><\/tr><tr><td>&lt;=<\/td><td>Less than or equal to<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id='equal-operator'>Equal operator (=) <a href=\"#equal-operator\" class=\"anchor\" id=\"equal-operator\" title=\"Anchor for Equal operator (=)\">#<\/a><\/h3>\n\n\n\n<p>The equal operator returns true if two values are equal.<\/p>\n\n\n\n<p>For example, the following statement uses the equal to operator (<code>=<\/code>) in the <code>WHERE<\/code> clause to query the products from the <code>inventories<\/code> with a quantity equal to <code>10<\/code>:<\/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\">name<\/span>, quantity\n<span class=\"hljs-keyword\">FROM<\/span> inventories\n<span class=\"hljs-keyword\">WHERE<\/span> quantity = <span class=\"hljs-number\">10<\/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.pgtutorial.com\/playground\/?db=where&amp;q=U0VMRUNUIG5hbWUsIHF1YW50aXR5IEZST00gaW52ZW50b3JpZXMgV0hFUkUgcXVhbnRpdHkgPSAxMDs\" 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\">     name      | quantity\n<span class=\"hljs-comment\">---------------+----------<\/span>\n iPhone 14 Pro |       10<\/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 query returns the <code>iPhone 14 Pro<\/code> because only this product has a quantity of 10.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='not-equal-operator'>Not equal operator ( !=) <a href=\"#not-equal-operator\" class=\"anchor\" id=\"not-equal-operator\" title=\"Anchor for Not equal operator ( !=)\">#<\/a><\/h3>\n\n\n\n<p>The following statement uses the not equal operator (<code>!=<\/code>) to retrieve products from the <code>inventories<\/code> table with the quantity not equal to 10:<\/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-keyword\">name<\/span>, quantity\n<span class=\"hljs-keyword\">FROM<\/span> inventories\n<span class=\"hljs-keyword\">WHERE<\/span> quantity != <span class=\"hljs-number\">10<\/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 href=\"https:\/\/www.pgtutorial.com\/playground\/?db=where&amp;q=U0VMRUNUIG5hbWUsIHF1YW50aXR5IEZST00gaW52ZW50b3JpZXMgV0hFUkUgcXVhbnRpdHkgIT0gMTA7\" 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-11\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">       name       | quantity\n<span class=\"hljs-comment\">------------------+----------<\/span>\n Galaxy S23 Ultra |       15\n Pixel 7 Pro      |        8\n Xperia 1 IV      |        7<\/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>Note that PostgreSQL also uses <code>&lt;&gt;<\/code> as the not equal to operator, so you can use the <code>!=<\/code> and <code>&lt;&gt;<\/code> operators interchangeably.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='the-where-clause-and-column-alias'>The WHERE clause and column alias <a href=\"#the-where-clause-and-column-alias\" class=\"anchor\" id=\"the-where-clause-and-column-alias\" title=\"Anchor for The WHERE clause and column alias\">#<\/a><\/h2>\n\n\n\n<p>Since PostgreSQL evaluates the <code>WHERE<\/code> clause before the <code>SELECT<\/code> clause, the column aliases are not available at the time of evaluating the <code>WHERE<\/code> clause.<\/p>\n\n\n\n<p>The following statement attempts to use the <code>amount<\/code> column alias in the <code>WHERE<\/code> and results in an error:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  <span class=\"hljs-type\">name<\/span>,\n  quantity * price <span class=\"hljs-keyword\">AS<\/span> amount\n<span class=\"hljs-keyword\">FROM<\/span>\n  inventories\n<span class=\"hljs-keyword\">WHERE<\/span>\n  amount &gt; <span class=\"hljs-number\">10000<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?db=where&amp;q=U0VMRUNUIG5hbWUsIHF1YW50aXR5ICogcHJpY2UgQVMgYW1vdW50IEZST00gaW52ZW50b3JpZXMgV0hFUkUgYW1vdW50ID4gMTAwMDA7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Error:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">column \"amount\" does not exist<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The output indicates that the <code>amount<\/code> column does not exist. To fix this error, you need to use the expression in the <code>WHERE<\/code> clause as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  <span class=\"hljs-type\">name<\/span>,\n  quantity * price <span class=\"hljs-keyword\">AS<\/span> amount\n<span class=\"hljs-keyword\">FROM<\/span>\n  inventories\n<span class=\"hljs-keyword\">WHERE<\/span>\n  quantity * price &gt; <span class=\"hljs-number\">10000<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?db=where&amp;q=U0VMRUNUIG5hbWUsIHF1YW50aXR5ICogcHJpY2UgQVMgYW1vdW50IEZST00gaW52ZW50b3JpZXMgV0hFUkUgcXVhbnRpdHkgKiBwcmljZSA%2BIDEwMDAwOw%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-15\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">       name       |  amount\n------------------+----------\n Galaxy S23 Ultra | 17999.85<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/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 <code>WHERE<\/code> clause to filter rows from a table based on a condition.<\/li>\n\n\n\n<li>PostgreSQL evaluates the <code>WHERE<\/code> clause after the <code>FROM<\/code> clause and before the <code>SELECT<\/code> clause.<\/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  src=\"\/quiz\/?quiz=where\"\n  height=\"700\"\n  width=\"600\"\n  class=\"iframe\"\n><\/iframe>\n\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=\"121\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-where\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL WHERE: Filtering Rows\"\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=\"121\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-where\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL WHERE: Filtering Rows\"\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>Summary: in this tutorial, you will learn how to use the PostgreSQL WHERE clause to filter rows in a table. PostgreSQL WHERE clause # The SELECT FROM statement retrieves data from one or more columns of all rows of a table. In practice, you often need to select rows that meet a condition. To filter [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":13,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-121","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>PostgreSQL WHERE: Filtering Rows<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn how to use the PostgreSQL WHERE clause to filter rows in a table based on a condition.\" \/>\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.pgtutorial.com\/postgresql-tutorial\/postgresql-where\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL WHERE: Filtering Rows\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn how to use the PostgreSQL WHERE clause to filter rows in a table based on a condition.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-where\/\" \/>\n<meta property=\"og:site_name\" content=\"PostgreSQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-01T09:24:40+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=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-where\\\/\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-where\\\/\",\"name\":\"PostgreSQL WHERE: Filtering Rows\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\"},\"datePublished\":\"2024-11-19T04:36:07+00:00\",\"dateModified\":\"2025-01-01T09:24:40+00:00\",\"description\":\"In this tutorial, you will learn how to use the PostgreSQL WHERE clause to filter rows in a table based on a condition.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-where\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-where\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-where\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL Tutorial\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PostgreSQL WHERE: Filtering Rows\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/\",\"name\":\"PostgreSQL Tutorial\",\"description\":\"Learn PostgreSQL from Scratch\",\"alternateName\":\"PostgreSQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pgtutorial.com\\\/?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":"PostgreSQL WHERE: Filtering Rows","description":"In this tutorial, you will learn how to use the PostgreSQL WHERE clause to filter rows in a table based on a condition.","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.pgtutorial.com\/postgresql-tutorial\/postgresql-where\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL WHERE: Filtering Rows","og_description":"In this tutorial, you will learn how to use the PostgreSQL WHERE clause to filter rows in a table based on a condition.","og_url":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-where\/","og_site_name":"PostgreSQL Tutorial","article_modified_time":"2025-01-01T09:24:40+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-where\/","url":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-where\/","name":"PostgreSQL WHERE: Filtering Rows","isPartOf":{"@id":"https:\/\/www.pgtutorial.com\/#website"},"datePublished":"2024-11-19T04:36:07+00:00","dateModified":"2025-01-01T09:24:40+00:00","description":"In this tutorial, you will learn how to use the PostgreSQL WHERE clause to filter rows in a table based on a condition.","breadcrumb":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-where\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-where\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-where\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL Tutorial","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":3,"name":"PostgreSQL WHERE: Filtering Rows"}]},{"@type":"WebSite","@id":"https:\/\/www.pgtutorial.com\/#website","url":"https:\/\/www.pgtutorial.com\/","name":"PostgreSQL Tutorial","description":"Learn PostgreSQL from Scratch","alternateName":"PostgreSQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pgtutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/comments?post=121"}],"version-history":[{"count":14,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/121\/revisions"}],"predecessor-version":[{"id":1316,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/121\/revisions\/1316"}],"up":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/13"}],"wp:attachment":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/media?parent=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}