{"id":599,"date":"2024-12-03T17:35:30","date_gmt":"2024-12-03T10:35:30","guid":{"rendered":"https:\/\/www.pgtutorial.com\/?page_id=599"},"modified":"2025-01-22T09:04:11","modified_gmt":"2025-01-22T02:04:11","slug":"postgresql-exists","status":"publish","type":"page","link":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-exists\/","title":{"rendered":"PostgreSQL EXISTS Operator"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn how to use the PostgreSQL <code>EXISTS<\/code> operator to check for the existence of rows returned by a subquery.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='getting-started-with-the-postgresql-exists-operator'>Getting Started with the PostgreSQL EXISTS Operator <a href=\"#getting-started-with-the-postgresql-exists-operator\" class=\"anchor\" id=\"getting-started-with-the-postgresql-exists-operator\" title=\"Anchor for Getting Started with the PostgreSQL EXISTS Operator\">#<\/a><\/h2>\n\n\n\n<p>In PostgreSQL, the <code>EXISTS<\/code> operator allows you to check if a <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-subquery\/\">subquery<\/a> returns at least one row. The <code>EXISTS<\/code> operator returns <code>true<\/code> if the subquery returns any rows or <code>false<\/code> otherwise.<\/p>\n\n\n\n<p>Here&#8217;s the syntax of the <code>EXISTS<\/code> operator:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" 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\">EXISTS<\/span> (subquery)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><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>To negate the result of the <code>EXISTS<\/code> operator, you use the <code>NOT<\/code> operator:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" 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\">NOT<\/span> <span class=\"hljs-keyword\">EXISTS<\/span> (subquery)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><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>Typically, you&#8217;ll use the <code>EXISTS<\/code> operator in the <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-where\/\">WHERE<\/a><\/code> clause of the <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-select\/\">SELECT<\/a><\/code>, <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-update\/\">UPDATE<\/a><\/code>, and <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-delete\/\">DELETE<\/a><\/code> statements.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='using-the-postgresql-exists-operator-in-select-statements'>Using the PostgreSQL EXISTS operator in SELECT statements <a href=\"#using-the-postgresql-exists-operator-in-select-statements\" class=\"anchor\" id=\"using-the-postgresql-exists-operator-in-select-statements\" title=\"Anchor for Using the PostgreSQL EXISTS operator in SELECT statements\">#<\/a><\/h2>\n\n\n\n<p>The following example uses the <code>EXISTS<\/code> operator to find all products stored in at least one warehouse:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" 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  product_name\n<span class=\"hljs-keyword\">FROM<\/span>\n  products p\n<span class=\"hljs-keyword\">WHERE<\/span>\n  <span class=\"hljs-keyword\">EXISTS<\/span> (\n    <span class=\"hljs-keyword\">SELECT<\/span>\n      <span class=\"hljs-number\">1<\/span>\n    <span class=\"hljs-keyword\">FROM<\/span>\n      inventories i\n    <span class=\"hljs-keyword\">WHERE<\/span>\n      i.product_id = p.product_id\n  );<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><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:\/\/pgtutorial.com\/playground\/?q=U0VMRUNUIHByb2R1Y3RfbmFtZSBGUk9NIHByb2R1Y3RzIHAgV0hFUkUgRVhJU1RTICggU0VMRUNUIDEgRlJPTSBpbnZlbnRvcmllcyBpIFdIRVJFIGkucHJvZHVjdF9pZCA9IHAucHJvZHVjdF9pZCApOw%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-4\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">       product_name\n---------------------------\n Sony Xperia 1 VI\n Samsung Galaxy Z Fold 5\n Samsung Galaxy Tab S9\n Apple iPad Pro 12.9\n Samsung Galaxy Buds Pro 2\n Apple Watch Series 9\n LG OLED TV C3\n Sony Bravia XR A95K\n LG G3 OLED\n Sony HT-A7000 Soundbar\n Dell XPS 15\n HP Spectre x360\n Lenovo ThinkPad X1 Carbon\n Apple iMac 24\"<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><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>In this example, the subquery checks if the <code>inventories<\/code> table has any row whose <code>product_id<\/code> equals <code>product_id<\/code> in the <code>products<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" 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-number\">1<\/span>\n<span class=\"hljs-keyword\">FROM<\/span>\n  inventories i\n<span class=\"hljs-keyword\">WHERE<\/span>\n  i.product_id = p.product_id<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><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>If the subquery returns any rows, the <code>EXISTS<\/code> operator returns true, and the outer query includes the product in the result set.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='using-the-postgresql-exists-operator-in-update-statements'>Using the PostgreSQL EXISTS operator in UPDATE statements <a href=\"#using-the-postgresql-exists-operator-in-update-statements\" class=\"anchor\" id=\"using-the-postgresql-exists-operator-in-update-statements\" title=\"Anchor for Using the PostgreSQL EXISTS operator in UPDATE statements\">#<\/a><\/h2>\n\n\n\n<p>The following statement increases the prices of all products in the warehouse id 1 by 5%:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" 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\">UPDATE<\/span> products p\n<span class=\"hljs-keyword\">SET<\/span>\n  price = price * <span class=\"hljs-number\">1.05<\/span>\n<span class=\"hljs-keyword\">WHERE<\/span>\n  <span class=\"hljs-keyword\">EXISTS<\/span> (\n    <span class=\"hljs-keyword\">SELECT<\/span>\n      <span class=\"hljs-number\">1<\/span>\n    <span class=\"hljs-keyword\">FROM<\/span>\n      inventories i\n    <span class=\"hljs-keyword\">WHERE<\/span>\n      i.product_id = p.product_id\n      <span class=\"hljs-keyword\">AND<\/span> i.warehouse_id = <span class=\"hljs-number\">1<\/span>\n  ) \n<span class=\"hljs-keyword\">RETURNING<\/span> *;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><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:\/\/pgtutorial.com\/playground\/?q=VVBEQVRFIHByb2R1Y3RzIHAgU0VUIHByaWNlID0gcHJpY2UgKiAxLjA1IFdIRVJFIEVYSVNUUyAoIFNFTEVDVCAxIEZST00gaW52ZW50b3JpZXMgaSBXSEVSRSBpLnByb2R1Y3RfaWQgPSBwLnByb2R1Y3RfaWQgQU5EIGkud2FyZWhvdXNlX2lkID0gMSApIFJFVFVSTklORyAqOw%3D%3D\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\"> product_id |        product_name        |  price  | brand_id | category_id\n------------+----------------------------+---------+----------+-------------\n          1 | Samsung Galaxy S24         | 1049.99 |        1 |           1\n          4 | Xiaomi Mi 14               |  839.99 |        4 |           2\n          7 | Apple iPhone 15 Pro Max    | 1364.99 |        2 |           3\n         10 | Apple AirPods Pro 3        |  262.49 |        2 |           5\n         13 | Samsung Galaxy Watch 6     |  367.49 |        1 |           6\n         16 | Samsung QN900C Neo QLED    | 3149.99 |        1 |           8\n         19 | Bose SoundLink Max         |  419.99 |        7 |           9\n         22 | Microsoft Surface Laptop 5 | 1364.99 |        9 |          11\n         25 | Dell Inspiron 27           | 1049.99 |        7 |          12<\/code><\/span><\/pre>\n\n\n<p>In this example, the subquery checks if the inventories table has any rows with the same <code>product _id<\/code> as the <code>product_id<\/code> in the <code>products<\/code> table and <code>warehouse_id<\/code> 1.<\/p>\n\n\n\n<p>If the subquery produces at least one row, the <code>EXISTS<\/code> operator returns true, and the <code>UPDATE<\/code> statement updates the product price.<\/p>\n\n\n\n<p>You&#8217;ll find <code>SELECT 1<\/code> in a subquery with the <code>EXISTS<\/code> operator is a common practice.<\/p>\n\n\n\n<p>The number 1 is a placeholder and doesn&#8217;t impact the query logic. Additionally, <code>SELECT 1<\/code> is efficient because it avoids the overhead of selecting data from the table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='using-the-postgresql-exists-operator-in-delete-statements'>Using the PostgreSQL EXISTS operator in DELETE statements <a href=\"#using-the-postgresql-exists-operator-in-delete-statements\" class=\"anchor\" id=\"using-the-postgresql-exists-operator-in-delete-statements\" title=\"Anchor for Using the PostgreSQL EXISTS operator in DELETE statements\">#<\/a><\/h2>\n\n\n\n<p>First, insert two new rows into the <code>products<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" 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\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span>\n  products (product_name, price, safety_stock, gross_weight, brand_id, category_id)\n<span class=\"hljs-keyword\">VALUES<\/span>\n  (<span class=\"hljs-string\">'Samsung Galaxy S25'<\/span>, <span class=\"hljs-number\">999.99<\/span>, <span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">0.36<\/span>, <span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>),\n  (<span class=\"hljs-string\">'Apple iPhone 17'<\/span>, <span class=\"hljs-number\">1299.99<\/span>, <span class=\"hljs-number\">20<\/span>, <span class=\"hljs-number\">0.41<\/span>, <span class=\"hljs-number\">2<\/span>, <span class=\"hljs-number\">1<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><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\/?q=SU5TRVJUIElOVE8gcHJvZHVjdHMgKCBwcm9kdWN0X25hbWUsIHByaWNlLCBzYWZldHlfc3RvY2ssIGdyb3NzX3dlaWdodCwgYnJhbmRfaWQsIGNhdGVnb3J5X2lkICkgVkFMVUVTICgnU2Ftc3VuZyBHYWxheHkgUzI1JywgOTk5Ljk5LCAxMCwgMC4zNiwgMSwgMSksICgnQXBwbGUgaVBob25lIDE3JywgMTI5OS45OSwgMjAsIDAuNDEsIDIsIDEpOw%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Second, delete the products that are not stored in any warehouse:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" 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\">DELETE<\/span> <span class=\"hljs-keyword\">FROM<\/span> products p\n<span class=\"hljs-keyword\">WHERE<\/span>\n  <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">EXISTS<\/span> (\n    <span class=\"hljs-keyword\">SELECT<\/span>\n      <span class=\"hljs-number\">1<\/span>\n    <span class=\"hljs-keyword\">FROM<\/span>\n      inventories i\n    <span class=\"hljs-keyword\">WHERE<\/span>\n      i.product_id = p.product_id\n  ) \n<span class=\"hljs-keyword\">RETURNING<\/span> *;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><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\/?q=REVMRVRFIEZST00gcHJvZHVjdHMgcCBXSEVSRSBOT1QgRVhJU1RTICggU0VMRUNUIDEgRlJPTSBpbnZlbnRvcmllcyBpIFdIRVJFIGkucHJvZHVjdF9pZCA9IHAucHJvZHVjdF9pZCApIFJFVFVSTklORyAqOw%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\"><span><code class=\"hljs\"> product_id |    product_name    |  price  | brand_id | category_id\n------------+--------------------+---------+----------+-------------\n         26 | Samsung Galaxy S25 |  999.99 |        1 |           1\n         27 | Apple iPhone 17    | 1299.99 |        2 |           1<\/code><\/span><\/pre>\n\n\n<p>In this example, the subquery checks if the <code>inventories<\/code> table has rows with the sample <code>product_id<\/code> as in the products table.<\/p>\n\n\n\n<p>The <code>NOT EXISTS<\/code> becomes true if the subquery returns no rows, causing the <code>DELETE<\/code> statement to delete the product.<\/p>\n\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>The PostgreSQL <code>EXISTS<\/code> operator returns true if the subquery produces any rows or false otherwise.<\/li>\n\n\n\n<li>Use the <code>EXISTS<\/code> operator to check based on data in the related table.<\/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=exists\"\n  height=\"700\"\n  width=\"600\"\n  class=\"iframe\"\n><\/iframe>\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=\"599\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-exists\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL EXISTS Operator\"\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=\"599\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-exists\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL EXISTS Operator\"\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 PostgreSQL EXISTS operator to check for the existence of rows returned by a subquery.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":13,"menu_order":52,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-599","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 EXISTS Operator<\/title>\n<meta name=\"description\" content=\"In this tutorial, you&#039;ll learn how to use the PostgreSQL EXISTS operator to check for the existence of rows returned by a subquery.\" \/>\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-exists\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL EXISTS Operator\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you&#039;ll learn how to use the PostgreSQL EXISTS operator to check for the existence of rows returned by a subquery.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-exists\/\" \/>\n<meta property=\"og:site_name\" content=\"PostgreSQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-22T02:04:11+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.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-exists\\\/\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-exists\\\/\",\"name\":\"PostgreSQL EXISTS Operator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\"},\"datePublished\":\"2024-12-03T10:35:30+00:00\",\"dateModified\":\"2025-01-22T02:04:11+00:00\",\"description\":\"In this tutorial, you'll learn how to use the PostgreSQL EXISTS operator to check for the existence of rows returned by a subquery.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-exists\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-exists\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-exists\\\/#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 EXISTS Operator\"}]},{\"@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 EXISTS Operator","description":"In this tutorial, you'll learn how to use the PostgreSQL EXISTS operator to check for the existence of rows returned by a subquery.","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-exists\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL EXISTS Operator","og_description":"In this tutorial, you'll learn how to use the PostgreSQL EXISTS operator to check for the existence of rows returned by a subquery.","og_url":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-exists\/","og_site_name":"PostgreSQL Tutorial","article_modified_time":"2025-01-22T02:04:11+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.pgtutorial.com\/postgresql-tutorial\/postgresql-exists\/","url":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-exists\/","name":"PostgreSQL EXISTS Operator","isPartOf":{"@id":"https:\/\/www.pgtutorial.com\/#website"},"datePublished":"2024-12-03T10:35:30+00:00","dateModified":"2025-01-22T02:04:11+00:00","description":"In this tutorial, you'll learn how to use the PostgreSQL EXISTS operator to check for the existence of rows returned by a subquery.","breadcrumb":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-exists\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-exists\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-exists\/#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 EXISTS Operator"}]},{"@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\/599","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=599"}],"version-history":[{"count":13,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/599\/revisions"}],"predecessor-version":[{"id":1775,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/599\/revisions\/1775"}],"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=599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}