Sie sind auf Seite 1von 4

Syntax:

Select colmn name

From table name 1

Union

Select colmn name

From table name 2

Select supplier id, supplier name

From suppliers

Where supplier id<=20

Union

Select sid,s,sname

From shop kepers

Where sname=’mrp’

Order by 1;

Difference bw union and union all operators;

Union operator removes duplicate rows

Union all doesnot remove duplicate

Syntax:

Select coloumn name

From tablename 1

Union all

Select colmn name

From table name 2


Oracle Join
Join is query that is used to combine rows from 2 or more tables views or materialized
views.it retrieves data from multiple tables and creates new tables.

Join conditions: There may be at least one join condition either in the FROM clause or in the
WHERE clause for joining 2 tables. It compares 2 columns from diff tables and combines
pair of rows, each containing one row from each table, for which join condition is true.

Types of Joins

1. Inner joins(simple joins)


2. Outer joins --1.left outer join 2. Right outer Joins 3. Full Outer join
3. Equi joins
4. Self joins
5. Cross joins(Cartesian products)
6. Anti joins
7. Semi joins

O Inner joins: It is the simplest and most common tupe ofjoin.it returns all rows from
multiple tables where join condition is met.

Syntax:

Select column

From table1

Inner Join table 2

On table 1,colmn=table2.colomn

Left outer Join: it returns all thee rows from the left table specified in ON condition and
only those rows from right table where the join condition is met.

Syntax:

Select suppliers id, suppliers. Supplier name, orders. Order no.

From suppliers LEFT OUTER JOIN orders

ON suppliers.suppliersid = orders.supplierid;
Right outer Join: it returns all thee rows from the right table specified in ON condition and
only those rows from right table where the join condition is met.

Syntax:

Select orders. Order no.orders.city

From suppliers RIGHT OUTER JOIN orders

ON suppliers.suppliersid = orders.supplierid;

Full outer Join: it returns all thee rows from the left hand table and right hand table.It places
NULL where the join condition is not met.

Syntax:

Select suppliers. Supplierid,suppliers. Supplier name, orders. Order no.

From suppliers FULL OUTER JOIN orders

ON suppliers.suppliersid = orders.supplierid;

Equi Join: it returns the matching column values of the associated tables. It uses a
comparison operator in the WHERE clause to refer equality.

Syntax:

Select colomn list

From table1,2…

ON table1.colomnname+table2.colomnname;

Self Join: It is a specific type. A table is joined with itself{(unary relationship).A self-join
simply specifies that each rows of a table is combined with it self and every other row of the
table.

Syntax:

Select a.colomn name,b.colomn name…

From table1,2…

where a..colmn field=b.colomnfield;


Cross Join: specifies that all rows from first table join with all row of second table. If there
are x rows in t1 and y rows in t2then cross join result set have x*y rows.it happens normally
when no matching join columns are specified.

In simple words you can say that if 2 tables in a join query have no join condition then the
oracle returns their Cartesian product.

Syntax:

Select *From customer , supplier;

Write an sql code to get the 3rd highest salary of an employee table

How can u select unique records from a table

Das könnte Ihnen auch gefallen