0% found this document useful (0 votes)
43 views27 pages

Experiment No.1: Computer Software and Applications - II

This document discusses SQL commands for data definition language (DDL) and data manipulation language (DML). It provides examples of using DDL commands like CREATE TABLE, ALTER TABLE, DROP TABLE, and DESCRIBE TABLE. It also demonstrates DML commands such as INSERT, SELECT, UPDATE, and DELETE. The document then discusses using the SELECT command with different clauses like SELECT, FROM, and WHERE to query data from database tables.

Uploaded by

Swajit Jadhav
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)
43 views27 pages

Experiment No.1: Computer Software and Applications - II

This document discusses SQL commands for data definition language (DDL) and data manipulation language (DML). It provides examples of using DDL commands like CREATE TABLE, ALTER TABLE, DROP TABLE, and DESCRIBE TABLE. It also demonstrates DML commands such as INSERT, SELECT, UPDATE, and DELETE. The document then discusses using the SELECT command with different clauses like SELECT, FROM, and WHERE to query data from database tables.

Uploaded by

Swajit Jadhav
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/ 27

Computer Software and Applications - II

EXPERIMENT NO.1

TITLE : To study and implement various DDL Commands.

DDL- Data Definition Language (DDL) statements are used to define the database structure or schema. Data
Definition Language understanding with database schemas and describes how the data should consist in the
database, therefore language statements like CREATE TABLE or ALTER TABLE belongs to the DDL. DDL is
about "metadata".

DDL includes commands such as CREATE, ALTER and DROP statements.DDL is used to CREATE, ALTER
OR DROP the database objects (Table, Views, Users).

 Data Definition Language (DDL) are used different statements :

 CREATE - to create objects in the database


 ALTER - alters the structure of the database
 DROP - delete objects from the database
 TRUNCATE - remove all records from a table, including all spaces allocated for the records are
removed
 COMMENT - add comments to the data dictionary
 RENAME - rename an object

CREATE TABLE
Syntax: Create table table name( fieldname1 datatype(),fieldname2 datatype()...);

ALTER TABLE
1. ADD
2.MODIFY

ADD
Syntax:alter table table name  ADD (fieldname datatype()...);

modify
syntax: Alter table table name modify (fieldname datatype()...);

DESCRIBE TABLE
Syntax: DESCRIBE TABLE NAME;

DROP TABLE
Syntax: DROP Table name;

COMMENT - add comments to the data dictionary

RENAME - rename a table


Synatax: rename table table name to new table name

Department of Mechanical Engineering 1


Computer Software and Applications - II

Examples : In this example we creates a table and insert the values.

Example : In the following figure shows the alter a table .

For Example : In this figure shows the describe command.

Department of Mechanical Engineering 2


Computer Software and Applications - II

EXPERIMENT NO.2

TITLE : To study and implement various DML Commands.

DML- Data Manipulation Language (DML) statements are used for managing data within schema objects DML
deals with data manipulation, and therefore includes most common SQL statements such SELECT, INSERT,
etc. DML allows to add / modify / delete data itself.
DML is used to manipulate with the existing data in the database objects (insert, select, update, delete).

DML Commands:
1.INSERT
2.SELECT
3.UPDATE
4.DELETE

*INSERT:
Syntax: INSERT INTO Table name values();

*SELECT:
Syntax: Select*from <table name>

*UPDATE:
Syntax: Update<table name> set to(calculation);

*DELETE:
Syntax: Delete form<table name>

Example : In the below figure shows the update and delete command on the given table.

Department of Mechanical Engineering 3


Computer Software and Applications - II

Department of Mechanical Engineering 4


Computer Software and Applications - II

EXPERIMENT NO.3

TITLE : To study & implement select command with different clause

PRIOR CONCEPTS: Data Definition language commands

NEW CONCEPTS : The most commonly used SQL command is SELECT statement.
The SQL SELECT statement is used to query or retrieve data from a table in the database. A
query may retrieve information from specified columns or from all of the columns in the
table. To create a simple SQL SELECT Statement, you must specify the column(s) name and
the table name. The whole query is called SQL SELECT Statement.

THEORY :-
The SQL SELECT statement queries data from tables in the database. The statement begins
with the SELECT keyword. The basic SELECT statement has 3 clauses:

 SELECT
 FROM
 WHERE

The SELECT clause specifies the table columns that are retrieved. The FROM clause
specifies the tables accessed. The WHERE clause specifies which table rows are used. The
WHERE clause is optional; if missing, all table rows are used.

For example,

SELECT name FROM s WHERE city='Rome'

This query accesses rows from the table - s. It then filters those rows where the city column
contains Rome. Finally, the query retrieves the name column from each filtered row. Using
the example s table, this query produces:

name
Mario

Department of Mechanical Engineering 5


Computer Software and Applications - II

A detailed description of the query actions:

 The FROM clause accesses the s table. Contents:

sno name city


S1 Pierre Paris
S2 John London
S3 Mario Rome

 The WHERE clause filters the rows of the FROM table to use those whose city
column contains Rome. This chooses a single row from s:

sno name city


S3 Mario Rome

 The SELECT clause retrieves the name column from the rows filtered by the WHERE
clause:

name
Mario
The remainder of this subsection examines the 3 major clauses of the SELECT statement,
detailing their syntax and semantics:

 SELECT Clause -- specifies the table columns retrieved


 FROM Clause -- specifies the tables to be accessed
 WHERE Clause -- specifies which rows in the FROM tables to use

Extended query capabilities are covered in the next sub-section.

SELECT Clause

The SELECT clause is mandatory. It specifies a list of columns to be retrieved from the
tables in the FROM clause. It has the following general format:
SELECT [ALL|DISTINCT] select-list
select-list is a list of column names separated by commas. The ALL and DISTINCT
specifiers are optional. DISTINCT specifies that duplicate rows are discarded. A duplicate
row is when each corresponding select-list column has the same value. The default is ALL,
which retains duplicate rows.

Department of Mechanical Engineering 6


Computer Software and Applications - II

For example,

SELECT descr, color FROM p


The column names in the select list can be qualified by the appropriate table name:
SELECT p.descr, p.color FROM p
A column in the select list can be renamed by following the column name with the new name.
For example:
SELECT name supplier, city location FROM s
This produces:
supplier location
Pierre Paris
John London
Mario Rome
The select list may also contain expressions. See Expressions.

A special select list consisting of a single '*' requests all columns in all tables in the FROM
clause. For example,

SELECT * FROM sp
sno pno qty
S1 P1 NULL
S2 P1 200
S3 P1 1000
S3 P2 200
The * delimiter will retrieve just the columns of a single table when qualified by the table
name. For example:
SELECT sp.* FROM sp
This produces the same result as the previous example.

An unqualified * cannot be combined with other elements in the select list; it must be stand
alone. However, a qualified * can be combined with other elements. For example,

SELECT sp.*, city


FROM sp, s
WHERE sp.sno=s.sno

sno pno qty city

Department of Mechanical Engineering 7


Computer Software and Applications - II

S1 P1 NULL Paris
S2 P1 200 London
S3 P1 1000 Rome
S3 P2 200 Rome

Note: this is an example of a query joining 2 tables. See Joining Tables.

FROM Clause

The FROM clause always follows the SELECT clause. It lists the tables accessed by the
query.

For example,
SELECT * FROM s
When the From List contains multiple tables, commas separate the table names. For example,
SELECT sp.*, city
FROM sp, s
WHERE sp.sno=s.sno
When the From List has multiple tables, they must be joined together. See Joining Tables.

Correlation Names
Like columns in the select list, tables in the from list can be renamed by following the table
name with the new name. For example,
SELECT supplier.name FROM s supplier
The new name is known as the correlation (or range) name for the table. Self joins require
correlation names.

WHERE Clause

The WHERE clause is optional. When specified, it always follows the FROM clause. The
WHERE clause filters rows from the FROM clause tables. Omitting the WHERE clause
specifies that all rows are used.

Following the WHERE keyword is a logical expression, also known as a predicate.

The predicate evaluates to a SQL logical value -- true, false or unknown. The most basic
predicate is a comparison:

Department of Mechanical Engineering 8


Computer Software and Applications - II

color = 'Red'
This predicate returns:

 true -- if the color column contains the string value -- 'Red',


 false -- if the color column contains another string value (not 'Red'), or
 unknown -- if the color column contains null.

Generally, a comparison expression compares the contents of a table column to a literal, as


above. A comparison expression may also compare two columns to each other. Table joins
use this type of comparison. See Joining Tables.

The = (equals) comparison operator compares two values for equality. Additional comparison
operators are:

 > -- greater than


 < -- less than
 >= -- greater than or equal to
 <= -- less than or equal to
 <> -- not equal to

For example,
SELECT * FROM sp WHERE qty >= 200
sno pno qty
S2 P1 200
S3 P1 1000
S3 P2 200
Note: In the sp table, the qty column for one of the rows contains null. The comparison - qty
>= 200, evaluates to unknown for this row. In the final result of a query, rows with a WHERE
clause evaluating to unknown (or false) are eliminated (filtered out).

Both operands of a comparison should be the same data type, however automatic conversions
are performed between numeric, datetime and interval types. The CAST expression provides
explicit type conversions;

SQL SELECT command

Department of Mechanical Engineering 9


Computer Software and Applications - II

What do we use SQL for? Well, we use it to select data from the tables located in adatabase.
Immediately, we see two keywords: we need to SELECT information FROM a table. We
have the most basic SQL structure:

Syntax : SELECT “column name” FROM “table name”

To illustrate the above example, assume that we have the following table:

Table Store Information

We shall use this table as an example throughout the tutorial. To select all the stores in this
table, we key in,
SELECT Store_name FROM Store_ Information

RESULT:
Store name
Los Angeles
San Diego
Los Angeles
Boston

Multiple column names can be selected, as well as multiple table names.

2) SQL DISTINCT
The SELECT keyboard allows us to grab all information from a column (or columns)

Department of Mechanical Engineering 10


Computer Software and Applications - II

On a table. This, of course, necessarily mean that there will be redundancies. What if we only
want to select each DISTINCT elements? This is easy to accomplish in SQL. All we need to
do is to add DISTINCT after SELECT.

The syntax is as follows:

SELECT DISTINCT “column_ name”


FROM “table_ name”
For example, to select all distinct stores in Table Store_ Information,
Table Store_ Information

we key in,

SELECT DISTINCT store_name FROM Store_ Information

RESULT:
Store name
Los Angeles
San Diego
Los Angeles
Boston
Retrieving data from a tables

The SELECT statement can be used to retrieve data from any or all columns from a table.
Say that you have a table called product, which consists product name, description, price,
and etc. This is the statement to retrieve all the columns from the table product.
SELECT * FROM product
SELECT – specifies retrieval command plus what to select.
* - stands for everything.

Department of Mechanical Engineering 11


Computer Software and Applications - II

In this case, In stands for every columns in a table.

FROM – specifies the table required to retrieve information from.


Now, say that we want to retrieve only the product name, description and price not
everything. Here is how you would accomplish it.

SELECT name, description price FROM product;

How about if we want search product by specific chrematistics? That is when WHERE clause
becomes handy. Where clause is used when only a subset of all the rows in a table Is
required. Here is how you would list the name the price of the products has the pricevalueless
than $100.

CONCLUSION:
___________________________________________________________________________
___________________________________________________________________________

EXPERIMENT NO.4

TITLE : Consider the employee database. Where the primaries are underlined & write the
queries using following clauses & also retrieve the data from the given database.
Employee (employee_name, street, city)
Works (employee_name, company_name, salary)
Company (company_name, city)

Department of Mechanical Engineering 12


Computer Software and Applications - II

Manages (employee_name, city)


i) Order By ii)Between iii)Group By iv)Having

THEORY:

GROUP BY clause:-
The GROUP BY clause will gather all the rows together that contains data in the
specified column(s) and will allow aggregate functions to be performed on the one or more
columns.

HAVING clause:-
The HAVING clause allows you to specify conditions on the rows for each group – in other
words, which rows should be selected is based on the conditions you specify. The having clause should
follow the GROUP BY clause if you are going to use it.

ORDER BY clause:-
ORDER BY clause is an optional clause which will allow you to display the results of your
query in a sorted order (either ascending order or descending order ) based on the columns that you
specify to order by.

The IN and BETWEEN conditional operator:-


The IN operator is really a set membership best operator. That is, it is used to best whether or
not a value{stated before the keyword IN}is “in ”the list of values provided after the keyword IN.
NEW CONCEPTS :
Prototype: GROUP BY clause syntax:

SELECT column1 in1,SUM(column2)


FROM “list-of-tables”
GROUP BY “column-list”;

HAVING clause syntax:


SELECT column1 FROM “list-of-tables”
GROUP BY “column-list” HAVING “condition”;

Department of Mechanical Engineering 13


Computer Software and Applications - II

ORDER BY clause syntax:


SELECT column 1 FROM “list-of-tables” ORDER BY “column-list” [ASC | DESC];

[ ]=optional

IN and between operator:


SELECT col1 FROM “list-of-table”
WHERE col2 IN (list-of-values);
SELECT col1 FROM col2 “list-of-table”
WHERE col2 BETWEEN value1 AND value2.

PROCEDURE:
Creation of database:

mysql>create table employee(empname varchar(30) primary key, street varchar(30), city varchar(30));

mysql>create table works(empname varchar(30) primary key, companyname varchar(30), salary


number(30));

mysql>create table company(companyname varchar(30), city varchar(30));

mysql>create table manages(empname varchar(30) primary key, managername varchar(30));

Inserting value in the table:

mysql>insert into employee values(‘jones’,’main’,’bosten’);


mysql >insert into employee values(‘smith’,’avenue’,’jorden’);
mysql >insert into employee values(‘brown’,’central’,’forthay’);
mysql >insert into employee values(‘peter’,’athens’,’losangeles’);
mysql >insert into employee values(‘calis’,’liberal’,’inwood’);

mysql >insert into works values('smith','ACL',3000);


mysql >insert into works values('brown','ATNT',5000);
mysql >insert into works values('jones','Samsung','10000);

Department of Mechanical Engineering 14


Computer Software and Applications - II

mysql >insert into works values('peter','ebay','22000);

mysql >insert into works values('calis','sim','17000);


mysql >insert into manages values('calis','lance');
mysql >insert into manages values('peter','kaif');
mysql >insert into manages values('smith','sam');
mysql >insert into manages values('jones','hary');
mysql >insert into manages values('brown','krit');
.
mysql >insert into company values('ACL','vegas');
mysql >insert into company values('ATNT','losangeles');
mysql >insert into company values('ebay','canacity');
mysql >insert into company values('samsung','columbia');
mysql >insert into company values('sim','singapore');

Queries using clauses:

1) Display the employee name, salary from database and display the result in ascending order
based on their salary.
mysql >select empname, salary from works order by salary;
EMPNAME SALARY
--------------------------------------
Smith 3000
brown 5000
jones 10000
calis 17000
peter 22000

2) Display the highest paid salary in each company.

mysql > select companyname, max(salary) from works group by companyname;


COMPANYNAME MAX(SALARY)
----------------------------------------------------------
ACL 3000

Department of Mechanical Engineering 15


Computer Software and Applications - II

ATNT 22000
Samsung 10000

3)Display employees with salary and companyname having salary in between 4000 and
20000.
mysql >SELECT EMPNAME, SALARY, COMPANYNAME
FROM WORKS
WHERE SALARY BETWEEN 4000 AND 20000;

EMPNAME SALARY COMPANYNAME


-----------------------------------------------------------------------
brown 5000 ATNT
jones 10000 Samsung
calis 17000 ATNT

4)Display employees with salary and company name having salary greater than 10000.

SELECT AVG(SALARY)
FROM WORKS
HAVING AVG(SALARY)>10000
GROUP BY COMPANYNAME;
mysql >DESCRIBE EMPLOYEE;

Name Null? Type


-----------------------------------------------------------------------
EMPNAME NOT NULL VARCHAR2(30)
STREET VARCHAR2(30)
CITY VARCHAR2(30)

CONCLUSION:

Department of Mechanical Engineering 16


Computer Software and Applications - II

___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

EXPERIMENT NO: 5

Title: Consider the previous database & perform the different Join operations which are as
follows: I) Inner Join II) Outer Join III) Right Outer Join IV) Full Outer Join

PRIOR CONCEPTS:
Joins:
A join is a query that combines rows form two or more tables, views. or materialized views.

Department of Mechanical Engineering 17


Computer Software and Applications - II

Oracle performs a join whenever multiple tables appear in the queries FROM clause. The
query's select list can select any columns for many of these tables. If any two of these tables
have a column name in common, then you must qualify all references o these columns
throughout the query with table names to avoid ambiguity.

Join Conditions:
Most join queries contain WHERE clause conditions that compare two columns, each from a
different table. Such a condition is called a join condition. To execute a join, Oracle combines
pair of rows, each containing one row from each table , for which the join condition evaluates
to TRUE . The columns in the join conditions need not also appear in the select list.

Outer Joins:
An outer join extends the result of simple join. An outer join returns all rows that satisfy the
join condition and also returns some or all of those rows from one table for which no rows
from the other satisfy the join condition.

NEW CONCEPTS:
Prototype:
 To write a query that performs an outer join of tables A and B and returns all rows from A (a
left outer join), use the LEFT [OUTER] JOIN syntax in the FROM clause, or apply the outer
join operator (+) to all columns of B in the WHERE clause. For all rows in A that have no
matching rows in B, Oracle returns null for any select list expressions containing columns of
B.
 To write a query that performs an outer join of tables A & B and returns all rows from B(a
right outer join), use the RIGHT [OUTER] JOIN syntax in the FROM clause , or apply the
outer join operator(+) to all columns of A in the join condition in the WHERE clause. For all
rows in B that have no matching rows in A, Oracle returns null for any select list expressions
containing columns of A.
 To write a query that performs an outer join and returns all rows from A and B, extended with
nulls if they do not satisfy the join conditions (a full outer join), use the FULL [OUTER] JOIN
syntax in the FROM clause.

PROCEDURE:

Department of Mechanical Engineering 18


Computer Software and Applications - II

Queries using joins:


1) Write a query using a join to display all information about employee.
mysql >SELECT
EMPLOYEE.EMPNAME, WORKS.COMPANYNAME, WORKS.SALARY
FROM EMPLOYEE, WORKS
WHERE EMPLOYEE.EMPNAME=WORKS.EMPNAME;

EMPNAME COMPANYNAME SALARY


Smith ACL 3000
Brown ATNT 5000
Jones Samsung 1000
Peter ATNT 22000
Calis ATNT 17000

2) Write a query using a LEFT OUTER join to display all information about employee.
mysql > SELECT
EMPLOYEE.EMPNAME, WORKS.COMPANYNAME, WORKS.SALARY
2 FROM EMPLOYEE, WORKS
3 WHERE EMPLOYEE.EMPNAME=WORKS.EMPNAME (+);
EMPNAME COMPANYNAME SALARY
------------------------- --------------------------------- -----------------
Jones Samsung 10000
Smith ACL 3000
Brown ATNT 5000
Peter ATNT 22000
Calis ATNT 17000
3)

Write a query using RIGHT OUTER JOIN display all information about employee.
mysql >SELECT
EMPLOYEE.EMPNAME, WORKS.COPMANYNAME, WORKS.SALARY
FROM EMPLOYEE, WORKS
WHERE EMPLOYEE.EMPNAME (+) = WORKS.EMPNAME;
EMPNAME COMPANYNAME SALARY
-----------------------------------------------------------------------------------------------------

Department of Mechanical Engineering 19


Computer Software and Applications - II

Smith ACL 3000


Brown ATNT 5000
Jones Samsung 10000
Peter ATNT 22000
Calis ATNT 17000

SELECT EMPLOYEE.EMPNAME, WORKS.COPMANYNAME, WORKS.SALARY


FROM EMPLOYEE FULL OUTER JOIN WORKS
WHERE EMPLOYEE.EMPNAME=WORKS.EMPNAME;
OBSERVATION:
mysql > DESCRIBE COMPANY;

Name Null? Type


-----------------------------------------------------------------------------------
COMPANYNAME VARCHAR2(30)
CITY VARCHAR2(30)

mysql >SELECT * FROM MANAGES;


EMPNAME MANAGERNAME
---------------------------------------------------------
Calis Lance
Peter Kaif
Smith Sam
Jones Hary
Brown Krit
Mysql> SELECT EMPLOYEE.EMPNAME, MANAGES.MANAGERNAME
FROM EMPLOYEE, MANAGES
WHERE EMPLOYEE.EMPNAME=MANAGES.EMPNAME;
EMPNAME MANAGERNAME
----------------------------------------------------------
Calis Lance
Peter Kaif
Smith Sam
Jones Hary

Department of Mechanical Engineering 20


Computer Software and Applications - II

Brown Krit
CONCLUSION:
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________

EXPERIMENT NO. :6

TITLE: Consider above database and perform all aggregate functions.


1. min 2.max 3.sum 4.count 5.avg

PRIOR CONCEPTS:
To study and understand the concept of different functions in Oracle and SQL plus

INTRODUCTION:

Department of Mechanical Engineering 21


Computer Software and Applications - II

Aggregate functions are functions that take a collection of values as input return single value
SQL. Offers files that built in a aggregate function are used to compute against returned
column of numeric data from select statement. They basically summaries return of particular
column selected data.
Aggregate functions are as follows:
1. min 2.max 3.sum 4.count 5.avg

NEW CONCEPTS:
1. Min (column):- Return the smallest value in the given data column.
2. Max (column):- Return the largest value in the given data column.
3. Sum (column):-Return the given column the sum of numeric value in given column.
The input sum must be a collective of numbers.
4. Avg (column):- Return the avg_value in given column

PROCEDURE:
AVG:
AVG (<DISTINCT>|<ALL>] <n>)
Select avg(expr) from table-name, where condition;

MIN:
MIN (<DISTINCT>|<ALL>] <expr>)
Select min (expr) from table-name, where condition;
MAX:
MAX (<DISTINCT>|<ALL>] <expr>)
Select max (expr) from table-name, where condition;

SUM:
SUM (<DISTINCT>|<ALL>] <expr>)
Select sum (expr) from table-name, where condition;

IMPLEMENTATION AND RESULT:


1. Display the average salary for company ‘Samsung’
mysql > select avg (salary)
from Works

Department of Mechanical Engineering 22


Computer Software and Applications - II

Where companyname =’Samsung’


AVG (SALARY)
200000

2. Display the lowest salary paid to employee in company ‘Samsung’


mysql > select min (salary)
2 from Works

MIN (SALARY)
100000

3. Display the maximum salary paid to employee in company ‘Samsung’


mysql > select max (SALARY)
From works
Where companyname = ’Samsung’

MAX (SALARY)
300000

4. Give some of total salaries paid to employee of Samsung.


mysql >select Sum (SALARY)
2 from works
3 Where companyname = ’Samsung’

Sum (SALARY)
600000

5. How many employees are having salary 17000 in ATNT?


mysql >Select count (SALARY)
from Works
where companyname=’ATNT’ and salary=17000;

Count (SALARY)
1

Department of Mechanical Engineering 23


Computer Software and Applications - II

6. How many rows are there in employee table?


mysql >select count (*) from Employee;
Count(*)

Observation:-
mysql >update Works set salary = 10000
2 where empname =’PETER’;
0 rows updated

mysql >update Manages set managername = ’MACK’


2 where empname=’PETER’;
1 row updated
mysql >select * from Manages;

Empname managername
Calis lance
Peter mack
Smith sam
Jones hary
Brown krit
CONCLUSION :-
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
EXPERIMENT NO-7

TITLE: Write a query to perform the different Set operations which are as fallows:
I) Union II) Intersect III) Except IV) Minus
PRIOR CONCEPT:
Consider the above & perform the different set operation which is as follows
I) Union II) Intersect III ) Except IV) Minus

NEW CONCEPTS:

Department of Mechanical Engineering 24


Computer Software and Applications - II

UNION STATEMENT:-Combine data from one or more select statement


UNION:-Combine the unique rows return by 2 select statements.
UNIONALL:-Combine the rows return by 2 SELECT statements (including all duplicates)
INTERSECT:-Return only those rows that are in *both* SELECT statement
MINUS:-Return the rows that are in the first SELECT but not second
To combine more than two selects simply nest the expression
SELECT expr1 UNION (SELECT expr2 UNION SELECT expr3)

PROTOTYPE:-In oracle 8i (and above) the UNION command has been largely replaced by
the new.
Syntax:
SELECT Command {UNION | UNION ALL | INTERSECT | MINUS}
SELECT Command
Procedure:
Queries using different set operations
1> write a query to retrieve information about city of the employee using
UNION ALL

mysql > SELECT Employee.city


from Employee, Company
where Employee.city = Company.cit
UNION ALL
select Company.city
from Company, Works
7where Company.companyname = Works.companyname;
CITY:-
Losangeles
Vegas
Losangles
Losangles
Losangles
Columbia
6 rows selected

Department of Mechanical Engineering 25


Computer Software and Applications - II

2>write a query to retrieve information about the city of the employee using UNION
(Display the cities of the employees same as that of company and companies specified in
work table)
mysql >Select Emplpyee.city
From Emplopyee,Company
where employee.city=Company.city
UNION
Select Company.city
From Company, Works
where Company.companyname=Works.companyname;

CITY:-
Columbia
Losangeles
Vegas

3>write a query to retrieve information about the city of the employee using INTERSECT
mysql >Select Employee.city
From Emoployee,Company
where Employee.city=Company.city
intersect
Select Company.city
From Company, Works
where Company.companyname=Works.companyname;
CITY:-
Losangeles

4>write a query to retrieve information about the city of the employee using MINUS
mysql >Select Employee.city
From Employee, Company
where Employee.city=Company.city
MINUS
Select Company.city
From Company, Works

Department of Mechanical Engineering 26


Computer Software and Applications - II

where Company.companyname = Works.companyname;


No row selected.

OBSERVATION:
mysql >Describe z2
NAME NULL? TYPE
EMPNAME NOT NULL varchar 2(30)
COMPANYNAME Varchar 2(30)
SALARY Number (30)
SQL>Select*from z2
EMPNAME COMPANYNAME SALARY
Smith ACL 3000
Brown ATNT 5000
Jones SAMSUNG 10000
Peter ATNT 22000
Calis ATNT 17000

CONCLUSION :-
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

Department of Mechanical Engineering 27

You might also like