Professional Documents
Culture Documents
QUERIES
TABLE CREATION:
SYNTAX:
Create table<tablename> (column definition);
QUERY:
SQL> create table empl(ename varchar(10),eno number(10),salary
number(12),dept_name varchar2(20));
Table created.
INSERTION:
SYNTAX:
Insert into<tablename>(values to the columns);
QUERY 1:
SQL> insert into empl values('sathya' ,'7','25000','IT');
1 row created.
QUERY 2:
SQL> insert into empl values('muthu','8','50000','AERONAUTICAL');
1 row created.
QUERY 3:
SQL> insert into empl values('vignesh','5','75000','ECE');
1 row created.
QUERY 4:
SQL> insert into empl values('sarathy','3','60000','EEE');
1 row created.
QUERY 5:
SQL> insert into empl values('gowtham','9','20000','CSC');
1 row created.
QUERY 6:
SQL> insert into empl values('santhosh','2','40000','IT');
1 row created.
QUERY 7:
gowtham
CSC
QUERY 3:
List the ename when salary greater than 25000 or eno>5.
SQL> select ename from empl where salary>25000 or eno>5;
ENAME
---------sathya
muthu
vignesh
sarathy
gowtham
6 rows selected.
QUERY 4:
List ename when salary>25000.
QUERY 5:
SQL> select ename from empl where salary>25000;
ENAME
---------muthu
vignesh
sarathy
santhosh
List ename when salary is greater than 25000 and eno = 2.
SQL> select ename from empl where salary>25000 and eno=2;
ENAME
---------santhosh
QUERY 6:
List the ename when salary is greater than 25000 and dno>5.
SQL> select ename from empl where salary>25000 and eno>5;
ENAME
---------muthu
QUERY 7:
Display eno,ename and salary for eno is odd number.
ENAME
SALARY
---------- -------------------gowtham
20000
sathya
25000
QUERY 11:
Display eno of the employee in AERONAUTICAL dept use count function.
SQL> select count(eno)from empl where dept_name='AERONAUTICAL';
COUNT(ENO)
----------
1
QUERY 12:
Display eno,ename and salary when dept=IT ,CSC,EEE.
SQL> select eno,ename,salary from empl where dept_name='IT' or
dept_name='CSC' or dept_name='EEE';
ENO
---------7
3
9
2
ENAME
SALARY
---------- -------------------sathya
25000
sarathy
60000
gowtham
20000
santhosh
40000
QUERY 13:
Display ename and eno in alphabetical order.
SQL> select eno,ename from empl order by ename;
ENO
ENAME
---------- ---------------9
gowtham
8
muthu
2
santhosh
3
sarathy
7
sathya
5
vignesh
6 rows selected.
QUERY 14:
Display the dept wise total salary.
SQL> select dept_name,sum(salary)from empl group by dept_name;
DEPT_NAME
SUM (SALARY)
-------------------- ------------------------AERONAUTICAL
50000
CSC
20000
ECE
75000
EEE
60000
IT
65000
QUERY 15: Display the dept wise total salary along with number of
employees in the dept.
SQL> select dept_name,sum(salary)from empl group by dept_name;
DEPT_NAME
SUM (SALARY)
-------------------- -------------------------
AERONAUTICAL
CSC
ECE
EEE
IT
50000
20000
75000
60000
65000
QUERY 16:
Display dept wise total salary along with number of employees in the dept
if the dept has more than one employee.
SQL> select dept_name,sum(salary),count(*) from empl group by dept_name
having count(*)>1;
DEPT_NAME
SUM(SALARY) COUNT(*)
-------------------- ----------- ---------------------------------IT
65000
2
Creating a new table from an existing table:
QUERY:
SQL> create table empl1 as select *from empl;
Table created
QUERY:
Copying records from one table to another.
SQL> select *from empl;
ENAME
ENO
SALARY
DEPT_NAME
----------------------- -------------------------- ------------------ --------------Sathya
7
25000
IT
Muthu
8
50000
AERONAUTICAL
Vignesh
5
75000
ECE
Sarathy
3
60000
EEE
Gowtham
9
20000
CSE
santhosh
2
40000
IT
SET OPERATIONS:
QUERY :
SQL> create table empl(ename varchar(10),eno number(10),salary
number(12),dept_name varchar2(20));
Table created.
QUERY :
ENAME
ENO
SALARY
DEPT_NAME
---------- ---------- ---------- -----------------------------------------------------Gowtham
9
20000
CSC
Muthu
8
50000
AERONAUTICAL
Santhosh
2
40000
IT
sarathy
3
60000
EEE
sathya
7
25000
IT
vignesh
5
75000
ECE
vinoth
1
24000
CIVIL
7 rows selected.
UNION ALL:
QUERY:
SQL> select *from empl1 union all select *from empl;
ENAME
ENO
SALARY
DEPT_NAME
---------- ---------- ---------- ----------------------------------------------sathya
7
25000
IT
muthu
8
50000
AERONAUTICAL
vignesh
5
75000
ECE
sarathy
3
60000
EEE
gowtham
9
20000
CSC
santhosh
2
40000
IT
sathya
7
25000
IT
muthu
8
50000
AERONAUTICAL
vignesh
5
75000
ECE
sarathy
3
60000
EEE
gowtham
9
20000
CSC
ENAME
ENO
SALARY DEPT_NAME
---------- ---------- ---------- -------------------santhosh
2
40000 IT
vinoth
1
24000 CIVIL
sathya
7
25000 IT
muthu
8
50000 AERONAUTICAL
vignesh
5
75000 ECE
sarathy
3
60000 EEE
gowtham
9
20000 CSC
santhosh
2
40000 IT
19 rows selected.
INTERSECTION:
QUERY:
Result:
Thus, the data manipulation language commands by using SQL have been
executed and verified successfully.