You are on page 1of 1

The SQL UNION Operator

This operator is used in order to combine the result set of two or more SELECT statement. The columns
in each SELECT statement should be in same order. They should have similar data types and statements
within UNION must have same number of columns.
UNION Syntax:

SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;
UNION ALL Syntax:

SELECT column_name(s) FROM table1
UNION ALL
SELECT column_name(s) FROM table2;

The SQL GROUP BY Statement


This statement makes groups of rows that contains the same values in summary rows.
GROUP BY Syntax:

SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);

The SQL EXISTS Operator


In order to test the existence of any record, the SQL EXIST operator is very useful. It returns true if the
sub query returns one or more record.
EXISTS Syntax:

SELECT column_name(s)
FROM table_name
WHERE EXISTS
(SELECT column_name  FROM table_name WHERE condition);

You might also like