0% found this document useful (0 votes)
31 views

TOPICMIDTERM

The document discusses different SQL operators like UNION, INTERSECT, EXCEPT, and JOIN operators. UNION combines result sets from multiple queries without duplicates. INTERSECT returns only rows common to both queries. EXCEPT returns rows that are in the first query but not the second. JOIN operators combine rows from two tables - INNER JOIN returns matches, LEFT and RIGHT JOIN return all rows from the left/right table with nulls for non-matches, and FULL JOIN returns all rows by filling nulls.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

TOPICMIDTERM

The document discusses different SQL operators like UNION, INTERSECT, EXCEPT, and JOIN operators. UNION combines result sets from multiple queries without duplicates. INTERSECT returns only rows common to both queries. EXCEPT returns rows that are in the first query but not the second. JOIN operators combine rows from two tables - INNER JOIN returns matches, LEFT and RIGHT JOIN return all rows from the left/right table with nulls for non-matches, and FULL JOIN returns all rows by filling nulls.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Left join - It Returns all rows from left table, even if there are no matches in the right table

Sql intersect - It is used to combine two select statements, but returns rows only from the first select
statement that are identical to the row in the second select statement

Join - Means for combining fields from two tables by using values common to each

Equi join - What is other term for inner join

Inner join - It creates a new result table by combining column values of two tables based upon the join
predicate

Sql except - It is used to combine two select statements, but returns rows only from the first select
statement that are not returned by the second select statement

Sql union clause - It combine the result of two or more select statement without returning any duplicate
rows

Union all -It combine the result of two or more select statement and also returning any duplicate rows

Right join - It returns all rows from the right table , even if there are no matches in the left table

TRUE- The except clause returns only rows, which are not in the second select statement

FALSE - To use the union clause each select statement must have different data type

FASLE- To use the union clause each select statement must have different number of columns selected

FALSE- The most important and frequently used of the joins is the full joins

TRUE- The joined table will contain all the records from both the tables and fill in nulls for missing
matches on the either side

RELATIONAL SET OPERATORS


DBMS supports relational set operators as well. The major relational set operators are union,
intersection and set difference. All of these can be implemented in DBMS using different
queries.

SQL UNION CLAUSE (UNION OPERATOR)

The SQL UNION clause/operator is used to combine the results of two or more SELECT
statements without returning any duplicate rows.
To use this UNION clause, each SELECT statement must have

 The same number of columns selected


 The same number of column expressions
 The same data type and
 Have them in the same order
But they need not have to be in the same length.

UNION removes all duplicates, if any form the data and only displays distinct values
If duplicates values are required in the resultant data, then UNION ALL is used

Syntax

The basic syntax of a UNION clause is as follows −


SELECT column1 [, column2 ]
FROM table1 [, table2 ]
[WHERE condition]

UNION

SELECT column1 [, column2 ]


FROM table1 [, table2 ]
[WHERE condition]
SQL INTERSECT CLAUSE (INTERSECTION OPTR)
The SQL INTERSECT clause/operator is used to combine two SELECT statements, but returns
rows only from the first SELECT statement that are identical to a row in the second SELECT
statement. This means INTERSECT returns only common rows returned by the two SELECT
statements.
Just as with the UNION operator, the same rules apply when using the INTERSECT operator.
MySQL does not support the INTERSECT operator.

Syntax

The basic syntax of INTERSECT is as follows.


SELECT column1 [, column2 ]
FROM table1 [, table2 ]
[WHERE condition]

INTERSECT

SELECT column1 [, column2 ]


FROM table1 [, table2 ]
[WHERE condition]

SQL EXCEPT/MINUS CLAUSE (SET DIFFERENCE)

The SQL EXCEPT clause/operator is used to combine two SELECT statements and returns rows
from the first SELECT statement that are not returned by the second SELECT statement. This
means EXCEPT returns only rows, which are not available in the second SELECT statement.
Just as with the UNION operator, the same rules apply when using the EXCEPT operator.
MySQL does not support the EXCEPT operator.

Syntax

The basic syntax of EXCEPT is as follows.


SELECT column1 [, column2 ]
FROM table1 [, table2 ]
[WHERE condition]

EXCEPT

SELECT column1 [, column2 ]


FROM table1 [, table2 ]
[WHERE condition]

SQL JOIN OPERATORS

A SQL JOINs clause is used to combine records from two or more tables in a database. A JOIN is
a means for combining fields from two tables by using values common to each

SAMPLE SYNTAX
SQL> SELECT ID, NAME, AGE, AMOUNT
FROM CUSTOMERS, ORDERS
WHERE CUSTOMERS.ID = ORDERS.CUSTOMER_ID;

Different Types of SQL JOINs


Here are the different types of the JOINs in SQL:

 INNER JOIN: Returns rows when there is a match in both tables


 LEFT JOIN: Returns all records from the left table, even if there are no matches from the
right table
 RIGHT JOIN: Returns all records from the right table, even if there are no matches from
the left table
 FULL JOIN: Returns rows when there is a match in one of the tables

The most important and frequently used of the joins is the INNER JOIN. They are also referred
to as an EQUIJOIN.
The INNER JOIN creates a new result table by combining column values of two tables (table1
and table2) based upon the join-predicate. The query compares each row of table1 with each
row of table2 to find all pairs of rows which satisfy the join-predicate. When the join-predicate
is satisfied, column values for each matched pair of rows of A and B are combined into a result
row.

Syntax

The basic syntax of the INNER JOIN is as follows.


SELECT table1.column1, table2.column2...
FROM table1
INNER JOIN table2
ON table1.common_field = table2.common_field;
The SQL LEFT JOIN returns all rows from the left table, even if there are no matches in the
right table. This means that if the ON clause matches 0 (zero) records in the right table; the
join will still return a row in the result, but with NULL in each column from the right table.
This means that a left join returns all the values from the left table, plus matched values from
the right table or NULL in case of no matching join predicate.

Syntax

The basic syntax of a LEFT JOIN is as follows.


SELECT table1.column1, table2.column2...
FROM table1
LEFT JOIN table2
ON table1.common_field = table2.common_field;

The SQL RIGHT JOIN returns all rows from the right table , even if there are no matches in the
left table. This means that if the ON clause matches 0 (zero) records in the left table; the join
will still return a row in the result, but with NULL in each column from the left table.
This means that a right join returns all the values from the right table, plus matched values
from the left table or NULL in case of no matching join predicate.

Syntax

The basic syntax of a RIGHT JOIN is as follow.


SELECT table1.column1, table2.column2...
FROM table1
RIGHT JOIN table2
ON table1.common_field = table2.common_field;

The SQL FULL JOIN combines the results of both left and right outer joins.
The joined table will contain all records from both the tables and fill in NULLs for missing
matches on either side.

Syntax

The basic syntax of a FULL JOIN is as follows −


SELECT table1.column1, table2.column2...
FROM table1
FULL JOIN table2
ON table1.common_field = table2.common_field;

You might also like