doc-exports/docs/dli/sqlreference/dli_08_0184.html
Su, Xiaomeng 04d4597cf3 dli_sqlreference_0511_version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
Co-committed-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
2023-11-02 14:34:08 +00:00

28 lines
3.3 KiB
HTML

<a name="dli_08_0184"></a><a name="dli_08_0184"></a>
<h1 class="topictitle1">INTERSECT</h1>
<div id="body8662426"><div class="section" id="dli_08_0184__en-us_topic_0093946995_s53b2ccb4d89c40b7ab272d30e13f0cb9"><h4 class="sectiontitle">Function</h4><p id="dli_08_0184__en-us_topic_0093946995_a2739bca8da6149d9adda2e9c43eb25c6">This statement is used to return the intersection set of multiple query results. </p>
</div>
<div class="section" id="dli_08_0184__en-us_topic_0093946995_sf5f553186db3478eaaaaf813d96cc273"><h4 class="sectiontitle">Syntax</h4><div class="codecoloring" codetype="Sql" id="dli_08_0184__screen115517214453"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="n">select_statement</span><span class="w"> </span><span class="k">INTERSECT</span><span class="w"> </span><span class="n">select_statement</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
</div>
<div class="section" id="dli_08_0184__en-us_topic_0093946995_s4fdc6bb7718648cba1bbc8e6e22542eb"><h4 class="sectiontitle">Keyword</h4><p id="dli_08_0184__en-us_topic_0093946995_ac79f620cd7cd4c3e9de44c2daa0188ec">INTERSECT returns the intersection of multiple query results. The number of columns returned by each SELECT statement must be the same. The column type and column name may not be the same. By default, INTERSECT deduplication is used.</p>
</div>
<div class="section" id="dli_08_0184__en-us_topic_0093946995_s7af9a82d936544548ce8bbaf42d16638"><h4 class="sectiontitle">Precautions</h4><p id="dli_08_0184__en-us_topic_0093946995_a21c4f8f6f2fa44e98ba66e07e67ce22f">Do not add brackets between multiple set operations, such as UNION, INTERSECT, and EXCEPT. Otherwise, an error is reported. </p>
</div>
<div class="section" id="dli_08_0184__en-us_topic_0093946995_sd68cd39b99454a6ab5c5247768f55557"><h4 class="sectiontitle">Example</h4><p id="dli_08_0184__en-us_topic_0093946995_ae2e815cf39fd4dde935140f1b7ead4f3">To return the intersection set of the query results of the <strong id="dli_08_0184__b189221247142616">SELECT * FROM student _1</strong> and <strong id="dli_08_0184__b39231347142613">SELECT * FROM student _2</strong> commands with the repeated records removed, run the following statement:</p>
<div class="codecoloring" codetype="Sql" id="dli_08_0184__screen18605131612458"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">student</span><span class="w"> </span><span class="n">_1</span><span class="w"> </span><span class="k">INTERSECT</span><span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">student</span><span class="w"> </span><span class="n">_2</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_0182.html">Set Operations</a></div>
</div>
</div>