-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexists.html
More file actions
33 lines (29 loc) · 1.63 KB
/
exists.html
File metadata and controls
33 lines (29 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!-- SECCIÓN EXISTS -->
<div id="exists-section">
<div id="adsense-container" style="width: 350px; position: absolute; left: 0px;"></div>
<div class="inner-modal">
<div class="inner" style="padding: 0px;">
<h1>SQL EXISTS Operator</h1>
<p>The EXISTS operator is used to test for the existence of any record in a subquery.</p>
<p>The EXISTS operator returns TRUE if the subquery returns one or more records.</p>
<p><strong>Note:</strong> SQL statements that use the EXISTS condition are very inefficient since the
sub-query is rerun for EVERY row in the outer query's table. There are more efficient ways to write most
queries, that do not use the EXISTS condition.</p>
<h2>EXISTS Syntax</h2>
<pre><code class="language-sql">SELECT column_name(s)
FROM table_name
WHERE EXISTS
(SELECT column_name FROM table_name WHERE condition);</code></pre>
<h2>SQL EXISTS Examples</h2>
<p>The following SQL statement returns all patients who were diagnosed with pregnancy:</p>
<pre><code class="language-sql">SELECT * FROM patients
WHERE EXISTS (SELECT diagnosis FROM admissions
WHERE patients.patient_id = admissions.patient_id
AND diagnosis = 'Pregnancy');</code></pre>
<p>The above SQL statement can be written more efficiently as:</p>
<pre><code class="language-sql">SELECT * FROM patients
JOIN admissions ON patients.patient_id = admissions.patient_id
WHERE diagnosis = 'Pregnancy';</code></pre>
</div>
</div>
</div>