<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.foji.io/index.php?action=history&amp;feed=atom&amp;title=Relational_Data_-_Operators_-_Exists</id>
	<title>Relational Data - Operators - Exists - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://docs.foji.io/index.php?action=history&amp;feed=atom&amp;title=Relational_Data_-_Operators_-_Exists"/>
	<link rel="alternate" type="text/html" href="https://docs.foji.io/index.php?title=Relational_Data_-_Operators_-_Exists&amp;action=history"/>
	<updated>2026-06-13T08:11:19Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://docs.foji.io/index.php?title=Relational_Data_-_Operators_-_Exists&amp;diff=2332&amp;oldid=prev</id>
		<title>Chris.Hansen: Import ClickHouse Docs: Wed Aug 28 2024 14:52:43 GMT-0400 (Eastern Daylight Time)</title>
		<link rel="alternate" type="text/html" href="https://docs.foji.io/index.php?title=Relational_Data_-_Operators_-_Exists&amp;diff=2332&amp;oldid=prev"/>
		<updated>2024-08-28T18:52:43Z</updated>

		<summary type="html">&lt;p&gt;Import ClickHouse Docs: Wed Aug 28 2024 14:52:43 GMT-0400 (Eastern Daylight Time)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The &amp;lt;code&amp;gt;EXISTS&amp;lt;/code&amp;gt; operator checks how many records are in the result of a subquery. If it is empty, then the operator returns &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt;. Otherwise, it returns &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;EXISTS&amp;lt;/code&amp;gt; can also be used in a [[Relational_Data_-_Statements_-_Select_-_Where|WHERE]] clause.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
References to main query tables and columns are not supported in a subquery.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Syntax&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;EXISTS(subquery)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Query checking existence of values in a subquery:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT EXISTS(SELECT * FROM numbers(10) WHERE number &amp;gt; 8), EXISTS(SELECT * FROM numbers(10) WHERE number &amp;gt; 11)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Result:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;┌─in(1, _subquery1)─┬─in(1, _subquery2)─┐&lt;br /&gt;
│                 1 │                 0 │&lt;br /&gt;
└───────────────────┴───────────────────┘&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Query with a subquery returning several rows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT count() FROM numbers(10) WHERE EXISTS(SELECT number FROM numbers(10) WHERE number &amp;gt; 8);&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Result:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;┌─count()─┐&lt;br /&gt;
│      10 │&lt;br /&gt;
└─────────┘&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Query with a subquery that returns an empty result:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT count() FROM numbers(10) WHERE EXISTS(SELECT number FROM numbers(10) WHERE number &amp;gt; 11);&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Result:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;┌─count()─┐&lt;br /&gt;
│       0 │&lt;br /&gt;
└─────────┘&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:Relational_Data]]&lt;/div&gt;</summary>
		<author><name>Chris.Hansen</name></author>
	</entry>
</feed>