You are on page 1of 8

SIMPLE

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:

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
CSC
santhosh
2
40000
IT
QUERY 8:
Find the names of all employee having m as the first letter in their name.
SQL> select ename,eno,salary from empl where ename like 'm%';
ENAME
ENO
SALARY
-------------------- ---------- ---------------muthu
8
50000
QUERY 9:
Find the names of all employee having g as the third letter in their name.
SQL> select ename,dept_name from empl where ename like '_.g%';
ENAME
DEPT_NAME
-------------------- ------------------------vignesh
ECE
SIMPLE QUERIES:
QUERY 1:
Display ename where eno is 7 or 8 or 5.
SQL> select ename from empl where eno=7 or eno=8 or eno=5;
ENAME
---------sathya
muthu
vignesh
QUERY 2:
Display ename,deptname where eno is 8 or 7 or 9.
SQL> select ename,dept_name from empl where eno=8 or eno=7 or eno=9;
ENAME
DEPT_NAME
---------- -------------------sathya
IT
muthu
AERONAUTICAL

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.

QUERY 8: SQL> select eno,ename,salary from empl where eno=9


or(mod(eno,7)=9);
ENO
---------9
7

ENAME
SALARY
---------- -------------------gowtham
20000
sathya
25000

Display eno,ename and salary for even numbers.


SQL> select eno,ename,salary from empl where eno=2 or(mod(eno,6)=8);
ENO
ENAME
SALARY
---------- ---------- -----------------------2
santhosh
40000
8
muthu
75000
QUERY 9:
Display ename when salary is between 20000 and 75000.
SQL> select ename from empl where salary between 20000 and 75000;
ENAME
---------sathya
muthu
vignesh
sarathy
gowtham
santhosh
6 rows selected.
QUERY 10:
Display ename when salary is 40000 or 60000 use any function.
SQL> select ename from empl where salary=any(40000,60000);
ENAME
---------sarathy
santhosh

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 :

SQL> insert into insert into empl1 values('vinoth','1','24000','CIVIL')


1 row created.
UNION:
QUERY: SQL> select *from empl1 union select *from empl;

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:

SQL> select *from empl1 intersect select *from empl;


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
6 rows selected.
MINUS:
QUERY:
SQL> select *from empl1 minus select *from empl;
ENAME
ENO
SALARY DEPT_NAME
---------- ---------- ---------- -------------------vinoth
1
24000
CIVIL

Result:
Thus, the data manipulation language commands by using SQL have been
executed and verified successfully.

You might also like