Professional Documents
Culture Documents
Experiment sql8 22
Experiment sql8 22
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.