Professional Documents
Culture Documents
B.S Anangpuria Institute of Technology and Management
B.S Anangpuria Institute of Technology and Management
B.S Anangpuria Institute of Technology and Management
S ANANGPURIA INSTITUTE OF
TECHNOLOGY AND MANAGEMENT
Submitted by:
Aditya NathTejpal
College Roll No.- 19/cs03
University Roll No.-19012004003
1|Page
INDEX
21. Write an SQL query to print details of the workers who have joined in
feb’2014
22. Write an SQL query to print details of the workers who are also
Managers.
23. Write an SQL query to fetch duplicate records having matching data in
some field of a table.
24. Write an SQL query to show the current and time.
25. Write an SQL query to show the top n(say 10) records of a table.
26. Write an SQL query to fetch the list of employees with the same salary.
27. Write an SQL query to show one row twice in resuls from a table.
28. Write an SQL query to fetch the first 50% records from a table.
29. Write an SQL query to print name of employees having the highest salary
in each department.
30. Write an SQL query to fetch the names of workers who earn the highest
salary.
3|Page
PRACTICAL – 1
HISTORY
SQL was initially developed at IBM by Donald D. Chamberlin and Raymond F. Boyce after
learning about the relational model from Edgar F. Coddin the early 1970s. This version,
initially called SEQUEL (Structured English Query Language), was designed to manipulate
and retrieve data stored in IBM's original quasirelational database management
system, System R, which a group at IBM San Jose Research Laboratory had developed
during the 1970s.
Chamberlin and Boyce's first attempt at a relational database language was SQUARE
(Specifying Queries in A Relational Environment), but it was difficult to use due to
subscript/superscript notation. After moving to the San Jose Research Laboratory in 1973,
they began work on a sequel to SQUARE.[12] The name SEQUEL was later changed to SQL
(dropping the vowels) because "SEQUEL" was a trademark of the UK-based Hawker
Siddeley Dynamics Engineering Limited company. [14] The label Structured Query Language
later became the acronym for SQL.
DATATYPES
A data type specifies a particular type of data, such as integer, floating-point, Boolean etc.
PRACTICAL – 2
Aim:To create table and insert values into it & show the table using select command.
Code:
create table avengers( Sr_No number(20), roll_number number(20), name varchar(20),
department varchar(10), section number(5), phoneno number(10));
insert into avengers values (1, 01, 'IRONMAN', 'cse', 1, 9561510564);
insert into avengers values (2, 02, 'CAPTAIN AMERICA', 'cse', 1, 9561510564);
insert into avengers values (3, 03, 'BLACK WIDDOW', 'cse', 1, 9561510564);
insert into avengers values (4, 04, 'THOR', 'cse', 1, 9561510564);
insert into avengers values (5, 05, 'HAWK EYE', 'cse', 1, 9561510564);
insert into avengers values (6, 06, 'SCARLET WITCH', 'cse', 1, 9561510564);
insert into avengers values (7, 07, 'VISION', 'cse', 1, 9561510564);
insert into avengers values (8, 08, 'HULK', 'cse', 1, 9561510564);
select * from avengers;
Output:
SR_NO ROLL_NUMBER NAME DEPARTMENT PHONENO SECTION
1 1 IRONMAN CSE 9561510564 1
2 2 CAPTAIN AMERICA CSE 9561510564 1
3 3 BLACK WIDOW CSE 9561510564 1
4 4 THOR CSE 9561510564 1
5 5 HAWK EYE CSE 9561510564 1
6 6 SCARLET WITCH CSE 9561510564 1
6|Page
PRACTICAL – 3
Aim :To use where clause for showing the table with condition select * table name
whereanything stored
Code:
create table avengers( Sr_No number(20), roll_number number(20), name varchar(20),
department varchar(10), section number(5), phoneno number(10));
insert into avengers values (1, 01, 'IRONMAN', 'IT', 1, 956470564);
insert into avengers values (2, 04, 'CAPTAIN AMERICA', 'cse', 1, 9561510564);
insert into avengers values (3, 43, 'BLACK WIDDOW', 'cse', 1, 9561510564);
insert into avengers values (4, 54, 'THOR', 'BCA', 1, 9561514254);
insert into avengers values (5, 35, 'HAWK EYE', 'IT', 1, 9561545218);
insert into avengers values (6, 52, 'SCARLET WITCH', 'cse', 1, 9532584564);
insert into avengers values (7, 17, 'VISION', 'IT', 1, 9561510114);
insert into avengers values (8, 28, 'HULK', 'cse', 1, 9561510564);
select * from avengers where department ='IT';
Output:
PRACTICAL – 4
Aim :To use Filtering Data from Database Using Employee Table.
Code:
create table Employee797897(Emp_id varchar2(4), Emp_Namevarchar(15), Emp_add
varchar(20), Salary number(10), Department varchar2(6));
insert into Employee797897values('&Emp_id, &Emp_Name, &Emp_add , &Salary,
&Department);
select* from Employee797897;
Output:
EMP_ EMP_NAME EMP_ADD SALARY DEPART
001 aaa 1111 block A 10000 IT
002 bbb 2222 block A 20000 CSE
003 ccc 3333 block A 15000 HR
004 ddd 4444 block A 25000 CSE
005 eee 5555 block A 30000 IT
006 fff 6666 block A 10000 IT
007 ggg 7777 block A 15000 HR
008 hhh 8888 block A 20000 CSE
009 iii 9999 block A 25000 CSE
010 jjj 1010 block A 15000 CSE
Output : -
EMP_ SALARY
001 10000
002 20000
003 15000
8|Page
004 25000
005 30000
006 10000
007 15000
008 20000
009 25000
010 15000
Output:-
EMP_ EMP_NAME EMP_ADD SALARY DEPART
002 bbb 2222 block A 20000 CSE
004 ddd 4444 block A 25000 CSE
008 hhh 8888 block A 20000 CSE
009 iii 9999 block A 25000 CSE
010 jjj 1010 block A 15000 CSE
Output:-
EMP_ SALARY
004 25000
9|Page
PRACTICAL – 5
Output:
EMP_ EMP_NAME EMP_ADD SALARY DEPART
001 aaa 1111 block A 10000 IT
002 bbb 2222 block A 20000 CSE
003 ccc 3333 block A 15000 HR
004 ddd 4444 block A 25000 CSE
005 eee 5555 block A 30000 IT
006 fff 6666 block A 10000 IT
007 ggg 7777 block A 15000 HR
008 hhh 8888 block A 20000 CSE
009 iii 9999 block A 25000 CSE
010 jjj 1010 block A 15000 CSE
001 aaa 1111 block A 10000 IT
Code :-
Select Distinct * from Employee797897;
Output:-
EMP_ EMP_NAME EMP_ADD SALARY DEPART
001 aaa 1111 block A 10000 IT
10 | P a g e
Output:
EMP_ EMP_NAME EMP_ADD SALARY DEPART
001 aaa 1111 block A 10000 IT
002 bbb 2222 block A 20000 CSE
003 ccc 3333 block A 15000 HR
004 ddd 4444 block A 25000 CSE
005 eee 5555 block A 30000 IT
006 fff 6666 block A 10000 IT
007 ggg 7777 block A 15000 HR
008 hhh 8888 block A 20000 CSE
009 iii 9999 block A 25000 CSE
010 jjj 1010 block A 15000 CSE
Code :-
select * from Employee797897
order by EMP_NAME desc;
Output:-
EMP_ EMP_NAME EMP_ADD SALARY DEPART
010 jjj 1010 block A 15000 CSE
11 | P a g e
Code :-
select * from Employee797897
order by EMP_NAME , DEPARTMENT ;
Output:-
EMP_ EMP_NAME EMP_ADD SALARY DEPART
001 aaa 1111 block A 10000 IT
001 aaa 1111 block A 10000 IT
002 bbb 2222 block A 20000 CSE
003 ccc 3333 block A 15000 HR
004 ddd 4444 block A 25000 CSE
005 eee 5555 block A 30000 IT
006 fff 6666 block A 10000 IT
007 ggg 7777 block A 15000 HR
008 hhh 8888 block A 20000 CSE
009 iii 9999 block A 25000 CSE
010 jjj 1010 block A 15000 CSE
12 | P a g e
PRACTICAL – 7
Aim :To create table from another table and insert values.
Code:
create table Employee797897(Emp_id varchar2(4), Emp_Namevarchar(15), Emp_add
varchar(20), Salary number(10), Department varchar2(6));
insert into Employee797897values('&Emp_id, &Emp_Name, &Emp_add , &Salary,
&Department);
select* from Employee797897;
Output:
EMP_ EMP_NAME EMP_ADD SALARY DEPART
001 aaa 1111 block A 10000 IT
002 bbb 2222 block A 20000 CSE
003 ccc 3333 block A 15000 HR
004 ddd 4444 block A 25000 CSE
005 eee 5555 block A 30000 IT
006 fff 6666 block A 10000 IT
007 ggg 7777 block A 15000 HR
008 hhh 8888 block A 20000 CSE
009 iii 9999 block A 25000 CSE
010 jjj 1010 block A 15000 CSE
Output:
Name Null? Type
EMP_ID VARCHAR2(4)
DEPARTMENT VARCHAR2(6)
Output:
EMP_ DEPART
001 IT
002 CSE
003 HR
004 CSE
005 IT
006 IT
007 HR
008 CSE
009 CSE
010 CSE
Output:
EMP_ DEPART
005 IT
006 IT
007 HR
008 CSE
009 CSE
010 CSE
15 | P a g e
PRACTICAL – 8
Output:
EMP_ EMP_NAME EMP_ADD SALARY DEPART
001 aaa 1111 block A 10000 IT
002 bbb 2222 block A 20000 CSE
003 ccc 3333 block A 15000 HR
004 ddd 4444 block A 25000 CSE
005 eee 5555 block A 30000 IT
006 fff 6666 block A 10000 IT
007 ggg 7777 block A 15000 HR
008 hhh 8888 block A 20000 CSE
009 iii 9999 block A 25000 CSE
010 jjj 1010 block A 15000 CSE
Output:
EMP_ EMP_NAME EMP_ADD SALARY DEPART
16 | P a g e
Output:
EMP_ EMP_NAME EMP_ADD SALARY DEPART
002 bbb 2222 block A 20000 CSE
003 ccc 3333 block A 15000 HR
004 ddd 4444 block A 25000 CSE
005 eee 5555 block A 30000 IT
006 fff 6666 block A 10000 IT
007 ggg 7777 block A 15000 HR
008 hhh 8888 block A 20000 CSE
009 iii 9999 block A 25000 CSE
010 jjj 1010 block A 15000 CSE
Output:
No output, Table doesn’t Exist
17 | P a g e
PRACTICAL – 9
Output:
EMP_ EMP_NAME EMP_ADD SALARY DEPART
001 aaa 1111 block A 10000 IT
002 bbb 2222 block A 20000 CSE
003 ccc 3333 block A 15000 HR
004 ddd 4444 block A 25000 CSE
005 eee 5555 block A 30000 IT
006 fff 6666 block A 10000 IT
007 ggg 7777 block A 15000 HR
008 hhh 8888 block A 20000 CSE
009 iii 9999 block A 25000 CSE
Output:
EMP_ EMP_NAME EMP_ADD SALARY DEPART
001 aaa 1111 block A 10000 CSE
002 bbb 2222 block A 20000 CSE
18 | P a g e