Blog Details

UNION Operator


                                
                                    <h2></h2>
<ul>
	<li><span style="font-size: 13px;">The <strong>UNION operator</strong> is used to <strong>combine</strong> the result-set of<strong> two or more SELECT statements.</strong></span></li>
</ul>
<ul>
	<li><span style="font-size: 13px;">Notice that each <strong>SELECT statement</strong> within the <strong>UNION</strong> must have the <strong>same number of columns</strong>. The columns must also have s<strong>imilar data</strong> <strong>types</strong>. Also, the columns in each <strong>SELECT statement</strong> must be in the <strong>same order.</strong></span></li>
</ul>
&nbsp;
<h3>UNION <strong>Syntax :</strong></h3>
SELECT <em>column_name(s)</em> FROM <em>table1</em>
<strong>UNION</strong>
SELECT <em>column_name(s)</em> FROM <em>table2</em>;

&nbsp;
<h3>UNION ALL Syntax:</h3>
SELECT <em>column_name(s)</em> FROM <em>table1</em>
<strong>UNION ALL</strong>
SELECT <em>column_name(s)</em> FROM <em>table2</em>;

&nbsp;
<h3>UNION Example:</h3>
SELECT City FROM Customers
UNION
SELECT City FROM Suppliers
ORDER BY City;

&nbsp;
<h3>UNION ALL Example:</h3>
SELECT City FROM Customers
UNION ALL
SELECT City FROM Suppliers
ORDER BY City;

&nbsp;
                                    


Categories

Php mysql

Latest posts

13.05.14
Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t

13.05.14
View

<ol> <li><a href="http://www.yiiframework.com/do

13.05.14
Creating Model

<ol> <li><a href="http://www.yiiframework.com/do

Get Free Quote