You are on page 1of 9

select * from city

insert into city values (&dept,'&city')

select * from help

create table city (deptno number(10),city varchar2(10))

select * from phone

select emp.deptno,emp.ename,dept.loc,city.city,phone.phone from emp join dept on


emp.deptno=dept.deptno join city on emp.deptno=city.deptno join phone on emp.deptno=phone.id

commit

select * from temp

select * from emp

select e.empno,e.ename,e.job,e.mgr,d.ename as manager,d.job "manager's_job" from emp e,emp d

where e.empno=d.mgr

select e.empno,e.ename,e.job,e.mgr,d.ename as manager,d.job "manager's_job" from emp e,emp d

where e.mgr=d.empno

select e.empno,e.ename,e.job,e.mgr,d.ename as manager,d.job "manager's_job" from emp e join emp


d

on e.mgr=d.empno
SELECT mgr from emp

group by mgr

select * from emp natural join dept;

select * from emp join dept using (deptno)

select * from emp join dept on (emp.deptno=dept.deptno)

select * from emp cross join dept

create TABLE b(id number(10),name varchar2(20))

select * from a

insert into b values(&id,'&name')

select * from a join b on a.id=b.id

create table tab1(id number(5))

insert into tab1 values(&id)


select * from tab1

create table tab2(id number(5))

insert into tab2 values(&id)

select * from tab2

alter table a modify id number(10) primary key

alter table a rename column name to ename

alter table a add city varchar2(10) default 'bangalore'

alter table a drop column city

alter table a add phone number(10) check(length(phone)=10)

alter table a

delete from a where id=6

update a set phone=null where id=4

delete from a

truncate table a

rename a to a1

drop table a1

insert into a values(&id,'&ename',&phone)

select * from a1

desc a

select * from tab1 join tab2 using (id)


select id from tab1 full join tab2 using (id)

commit

select * from emp

select * from dept

select max(sal),min(sal),avg(sal),sum(sal) from emp

Select A.ename, A.sal,a.job, B.dname,b.loc

From emp A, dept B

Where A.deptno = B.deptno

And A.job='MANAGER'

and b.loc='NEW YORK'

Order by A.sal ;

select deptno,max(sal)

from emp

where deptno in(10,20,30)

group by deptno

order by deptno
select deptno,max(sal),ename,job from emp

where deptno in(10,20,30)

group by deptno,ename,job

having

select count(comm) from emp

select job ,sum(sal) as "total salary" from emp

group by job

order by 2

select deptno,count(*),sum(sal) from emp

group by deptno

select deptno,job,count(*) from emp

where deptno in(10,20,30)

group by deptno,job

having count(*)>1

order by deptno

select deptno,job,max(sal),max(comm) from emp

where deptno not in 30


group by deptno,job

order by 3 desc

select deptno,count(*) as "employees" from emp

group by deptno

having count(*)>4

order by 1

select ename,job,max(sal) from emp

where ename not like '%S'

group by job,

order by 3

select deptno,sum(sal) from emp

group by deptno

having sum(sal)>9000

select * from user_constraints where table_name in ('EMP')

select * from emp

select distinct ename from emp

select job,count(*) from emp

group by job

having count(*)>1
create table tab2(id number(10))

insert into tab2 values(&id)

select * from tab1,tab2 where tab1.id=tab2.id

select * from emp where empno in (select mgr from emp)

select deptno,mgr,count(*) from emp

group by mgr,deptno

having count(*)=1;

select deptno from emp

group by deptno

having count(*)>1

create view city_view as select * from city

select * from city_view

delete from city_view where deptno=30


select distinct (d.dname) from dept d left join emp e

on e.deptno=d.deptno

minus

select distinct (d.dname) from dept d right join emp e

on d.deptno=e.deptno

select distinct (d.dname) from dept d full join emp e

on d.deptno<e.deptno

select distinct deptno,ename from emp

select * from emp1

desc emp

insert into emp1 select * from emp

where empno=7566

select * from emp1

create table emp1 as select * from emp

select * from user_constraints where table_name in ('EMP1')

alter table emp1 drop constraint SYS_C007359

commit

select * from emp

where job='CLERK'
select job from emp

group by job

select ename,sal,comm,sum(sal+comm) "total salary" from emp

group by sal,ename,comm

order by 4 asc

select ename,sal,comm,(sal+nvl(comm,0)) "total salary" from emp

group by sal,ename,comm

order by 4

You might also like