You are on page 1of 9

EXPERIMENT 8

Aim: Usage of where, like, in, all ,any, exists clauses.

Program: Like command:


create table emp(id int, name varchar(20));
insert into emp values(1,'varun');
insert into emp values(2, 'arun');
insert into emp values(3, 'karuna');
insert into emp values(4, 'amrit');
insert into emp values(5, 'ranjeet');
insert into emp values(6, 'ajeet');
select * from emp;
select * from emp where name like 'a%';
select name from emp where name like '%a';
select * from emp where name like '%n';
select * from emp where name like '%ee%';
select name from emp where name like 'a%';
select name from emp where name like '%ee%';
select * from emp where name like '_a%';
select * from emp where name like '_a___';
drop table emp;
Output:
where, In/not in, any, all clause:
create table student(sid int, sname varchar(20), marks int);
insert into student values(1,'sumit',78);
insert into student values(2,'ashu',79);
insert into student values(3,'shreya',85);
insert into student values(4,'priya',76);
insert into student values(5,'ram',87);
insert into student values(6,'tina',65);
select * from student;
select sname from student where sid=2;
select sname from student where marks=78 or marks=65 or marks=87;
select sname from student where marks in (78,65,87);
select sname from student where marks not in (78,65,87);
select sname from student where marks<78 or marks<67 or marks<86;
select sname from student where marks< any (78,67,86);
select sname from student where marks>78 or marks>67 or marks>86;
select sname from student where marks> any (78,67,86);
select sname from student where marks<78 or marks<67 or marks<86;
select sname from student where marks< all (78,67,86);
select sname from student where marks>78 and marks>67 and marks>86;
select sname from student where marks> all (78,67,86);
drop table student;

Output:
In/Not in, exists/Not exists
create table emp(eid int, ename varchar(20), address varchar(20), primary key(eid));
insert into emp values(1,'ravi','chd');
insert into emp values(2,'varun','delhi');
insert into emp values(3,'nitin','pune');
insert into emp values(4,'robin','bang');
insert into emp values(5,'ammy','chd');
select * from emp;
create table project(eid int, pid varchar(20), pname varchar(20), location varchar(20),
primary key(pid), foreign key(eid) references emp(eid));
insert into project values(1, 'p1', 'iot', 'bang');
insert into project values(5, 'p2', 'bd', 'delhi');
insert into project values(3, 'p3', 'retail', 'mumbai');
insert into project values(4, 'p4', 'android', 'hyd');
select * from project;
select * from emp where address in ('delhi','chd','pune');
select * from emp where address not in ('delhi','chd','pune');
select ename from emp where eid in (select distinct (eid) from project);
select ename from emp where eid not in (select distinct (eid) from project);
select * from emp where exists(select eid from project where emp.eid = project.eid);
select * from emp where not exists(select eid from project where emp.eid = project.eid);
drop table project;
drop table emp;

Output:
Conclusion: In this way, we could implement use where, like, in, all ,any, exists clauses.

You might also like