SELECT *FROM college;
select * from college where city IN('pune','ahmednager');
UPDATE college set city='nagpur' WHERE cno=103;
UPDATE college set city='Dhule' WHERE cno=107;
select MAX(college.salary) from college;
select MIN(college.salary) from college;
select SUM(college.salary) from college;
select * from college WHERE salary is null;
select COUNT(college.cno) from college;
select * from college order BY college.salary;
SELECT * FROM college ORDER BY college.salary desc;
select count(college.salary)as member from college where salary not between 10000
and 12000;
select count(college.salary)as member from college where salary not between 7000
and 10000;
select count(college.salary)as member from college where salary between 7000 and
10000;
select upper(college.cname) from college;
select lower(college.cname) from college;
select initcap(college.cname) from college;
select ltrim(college.cname) from college;
select rtrim(college.cname) from college;
select length(college.cname) from college;
select count(DISTINCT(college.city)) from college;
select DISTINCT(college.city) from college;
select cno,sum(college.salary) as TotalSal from college GROUP BY cno ;
select * from dept;
select * from emp;
select deptno ,sum(sal) as totalsal from emp group by deptno ;
create table emp1 as(select * from emp);
select * from emp1;
select * from emp MINUS(select * from emp1);
(select * from emp )INTERSECT(select * from emp1);
(select * from emp )UNION(select * from emp1);
select * from emp where sal>=1000 and sal<=2000;
select * from emp where sal BETWEEN 1000 and 2000;
===how to create table using existing table without value====
create table emp2 as select * from emp where 1=2;
==============================
Select * From College;
Select Cno,Sum(College.Salary) As Totalsal From College Group By Cno ;
Select * From Dept;
Select * From Emp;
Select Deptno ,Sum(Sal) As Totalsal From Emp Group By Deptno ;
Create Table Emp1 As(Select * From Emp);
Select * From Emp1;
Select * From Emp Minus(Select * From Emp1);
(Select * From Emp )Intersect(Select * From Emp1);
(Select * From Emp )Union(Select * From Emp1);
Select * From Emp Where Sal>=1000 And Sal<=2000;
Select * From Emp Where Sal Between 1000 And 2000;
Create Table Emp2 As Select * From Emp Where 1=2;
Select * From Emp2;
Drop Table Emp2;
Select Count(Ename) From Emp Where Sal>=3000;
Select * From Emp Where Sal<3000;
select * from emp;
Select * From Emp WHERE Sal>All(Select Sal From Emp Where Sal<3000);
Select * From Emp WHERE Sal>ANY (Select Sal From Emp Where Sal<3000);
select ename,sal,comm,(sal+nvl(comm,0)) as totalsal from emp;
select count(MGR),count(sal) from emp;
select * from emp where ename LIKE'%R';
select * from emp where ename LIKE'S_____';
select * from emp WHERE ename IN('BLAKE','SCOTT','KING','FORD');
select * from emp where job not in('SALESMAN','CLERK');
select * from emp where job in('SALESMAN','CLERK');
select ename,sal/12 as monthlySal from emp;//monthly wise salary of every employee
select * from dept;
--Count the number of employees in department wise
select count(empno),b.deptno,dname from emp a,dept b where a.deptno(+)=b.deptno
group by b.deptno,dname;
select max(rowid) from emp;
select * from emp a where rowid=(select max(rowid) from emp b where
a.empno=b.empno);//distinict employee from emp table
select distinct(job) from emp;
select distinct(empno) from emp;
select count(distinct(sal)) from emp;
select distinct hiherdate from emp a where &n=(select count(distinct(sal) from emp
b where a.sal>=b.sal);//command not run
select distinct sal from emp a where 3>=(select count(distinct sal) from emp b
where a.sal<=b.sal)order by a.sal desc;
select count(distinct sal) from emp a,emp b where a.sal<=b.sal;
select count(distinct(b.sal))from emp a,emp b where a.sal>=b.sal;
select * from emp;
select distinct sal from emp a where 3>=(select count(distinct sal) from emp b
where a.sal>=b.sal);
select distinct(b.sal) from emp a,emp b where a.sal>=b.sal;
select sal from emp order by sal desc 5,0;
select max(sal) from emp;
select max(sal) from emp where sal not in(5000);
select max(sal) from emp where sal not in(select max(sal) from emp);
select * from emp where sal=(select max(sal) from emp where sal>(select max(sal)
from emp));
select max(sal) from emp where sal<(select max(sal) from emp);
select min(sal) from emp where sal=(select min(sal) from emp);
select * from emp where sal=(select min(sal) from emp);
select * from emp where sal=(select max(sal) from emp where sal<(select max(sal)
from emp));
select * from emp where sal=(select min(sal) from emp where sal>(select min(sal)
from emp));
select TOP 4 * from emp;
select *from emp where rownum<=3;
=============
select deptno,count(deptno) from emp group by(deptno);
select job,count(job),count(empno),sum(sal) from emp group by job;
select sal from emp order by sal;
select sal from emp order by sal desc;
select deptno,sum(sal) from emp group by deptno;
select deptno,max(sal) from emp group by deptno;
select job,sum(sal) from emp group by job;
select job,min(sal) from emp group by job;
select deptno,count(deptno) from emp group by deptno HAVING count(*)>3;
select job,sum(sal) from emp group by job having sum(sal)>40000;
select job,sum(sal) from emp group by job having sum(sal)>8000;
select job,sum(sal) from emp group by job having sum(sal)<6000;
select job,count(empno) from emp group by job having count(job)>3;
SELECT ename from emp where sal=(select max(sal) from emp);--maximum salary
employee name
select ename,sal from emp where job='SALESMAN' and sal>(select max(sal) from emp
where job='CLERK');
select ename,sal from emp where job='CLERK' AND SAL>(SELECT min(sal) from emp where
job='SALESMAN');
----------
select ename,sal from emp where job='SALESMAN' and sal>(select max(sal) from emp
where job='CLERK');
select ename,sal from emp where job='CLERK' AND SAL>(SELECT min(sal) from emp where
job='SALESMAN');
select ename,sal from emp where sal>(select sal from emp where ename='JONES')and
sal>(select sal from emp where ename='SCOTT');
SELECT* FROM EMP;
SELECT ENAME,SAL,DEPTNO FROM EMP WHERE SAL IN(SELECT MAX(SAL) FROM EMP GROUP BY
DEPTNO);
SELECT DEPTNO,MAX(SAL) FROM EMP GROUP BY DEPTNO;
SELECT ENAME,SAL,JOB FROM EMP WHERE SAL IN(SELECT MAX(SAL) FROM EMP GROUP BY JOB);
SELECT ENAME,deptno FROM EMP WHERE DEPTNO=(SELECT DEPTNO FROM DEPARTMENT WHERE
DNAME='Accounting')
SELECT * FROM DEPARTMENT;
select ename,deptno from emp where deptno=(select deptno from department where
location='Chicago');
select job,sum(sal) from emp group by job having sum(sal)>(select max(sal) from emp
where job='MANAGER');
select ename from emp where deptno=10 and sal>any(select sal from emp where deptno
not in 10);
SELECT LENGTH('SHARAD') FROM DUAL;
SELECT LENGTH(ENAME) FROM EMP;
SELECT ENAME||' '||EMPNO FROM EMP;
SELECT SUBSTR('Oracle',3,2) from dual;
select INSTR('Computer Maintenance Coperation','a',1) from dual;
select translate('Allens','A','B') from dual;
select replace(JOB,'MANAGER','BOSS') FROM EMP;
select
empno,ename,decode(deptno,10,'ACCOUNTING',20,'RESEARCH',30,'SALES',40,'OPRATIONS')f
rom emp;
select (to_date(sysdate)-to_date('17_FEB-1988'))from dual;-- find age of days
select (to_date(sysdate)-to_date('17-FEB-88'))as days from dual;
select months_between(sysdate,'17-feb-88') from dual;---find age of months
select to_char(sysdate,'ddth month day year')from dual;--display date day month and
year in character
select ename||' '||'has joined the company on'||' '||to_char(HIREDATE,'day ddth
month year') from emp;--to show the hiredate into the chatacter
select next_day(sysdate,'Saturday')from dual;--find next Saturday
select to_char(sysdate,'hh:mm:ss') from dual;-- display the current time.
select add_months(sysdate,3) from dual;-- Display the date three months After the
current date.
select add_months(sysdate,-3) from dual;-- Display the date three months Before the
current date.
select job from emp where deptno=10 and job in(select job from emp where
deptno=20);
select distinct(job) from emp where deptno in(10,20);
select distinct(job) from emp where deptno=10;
select e.ename from emp,emp e where emp.MGR=e.empno group by e.ename having
count(*)>1;
select deptno from dept where dname='SALES';--30
select losal from salgrade where grade=3--output 1401
select hisal from salgrade where grade=3--2000
select losal,hisal from salgrade where grade=3;
select * from salgrade;
select * from emp where deptno=(select deptno from dept where
dname='SALES')and sal between(select losal from salgrade where
grade=3)and(select hisal from salgrade where grade=3);
select sal from emp where sal between 1400 and 2000 and deptno=30;
select distinct(m.ename),m.job from emp e,emp m where m.empno=e.mgr;
select ename from emp where length(ename)>4;
select dname from dept where DNAME Like 'J%' and LOC like '%S';
=================NEW REPETED SQL QUERY==========
select * from emp;
select * from department;
select * from salgrade;
select ename,job from emp;
select ename,sal from emp;
select ename,empno,sal,comm,sal+nvl(comm,0)as totalsal from emp;
select ename ,12*(sal+nvl(comm,0))as AnnualSal from emp;
select ename from emp where deptno=10;
select ename from emp where job='CLERK' and sal>3000;
select ename from emp where job='CLERK' and sal>3000;
SELECT ENAME,comm FROM EMP WHERE COMM IS NOT NULL;
select ename,comm from emp where comm is null;
select ename,job,sal from emp where sal>3000 and job='CLERK'or job='ANALYST'or
job='SALESMAN';
SELECT ENAME,sal FROM EMP WHERE SAL>3000;
select ename,SAL,job from emp where job='CLERK' OR JOB='SALESMAN' OR JOB='ANALYST'
AND SAL>3000;
SELECT ename,sysdate,hiredate,to_char(sysdate,'yyyy')-to_char(hiredate,'yyyy')as
count from emp where to_char(sysdate,'yyyy')-to_char(hiredate,'yyyy')>=5;
select ename,hiredate from emp where hiredate<'30-JUN-1981' or hiredate>'31-DEC-
1985';
select sysdate from dual;
select username from all_users;
select tname from tab;
show USER;
select ename,deptno,JOB from emp where deptno in(10,20,40) OR job
in('CLERK','ANALYST','SALESMAN');
select ename,DEPTNO,JOB from emp where deptno in(10,20,40) and job
in('CLERK','ANALYST','SALESMAN');
select ename from emp where ename like'S%';
select ename from emp where ename like'%S';
select ename from emp where ename like'S%';
select ename from emp where ename like'_A%';
select ename from emp where length(ename)=5;
select ename,job from emp where job not in('MANAGER');
SELECT ename,JOB from emp where job not in('CLERK','SALESMAN','ANALYST');
SET PAUSE ON;
SELECT COUNT(*) FROM EMP;
SELECT SUM(SAL) FROM EMP;
SELECT max(sal) from emp;
SELECT AVG(SAL) FROM EMP;
SELECT MAX(SAL) FROM EMP WHERE JOB='CLERK';
SELECT MAX(SAL) FROM EMP WHERE DEPTNO=20;
SELECT MIN(SAL) FROM EMP WHERE JOB='SALESMAN';
SELECT SAL FROM EMP WHERE JOB='MANAGER';
SELECT SUM(SAL)/3 AS AVG FROM EMP WHERE JOB='MANAGER';
SELECT AVG(SAL) FROM EMP WHERE JOB='MANAGER';
SELECT SUM(SAL) FROM EMP WHERE DEPTNO=40 AND JOB='ANALYST';
select ename from emp order by sal;
SELECT ENAME,SAL FROM EMP ORDER BY SAL DESC;
select ename from emp order by ename desc;
select empno,ename,sal,deptno from emp order by ename;
select ename,sal,(sal*0.15)as HRA,(sal*0.10)as DA,(sal*0.05)as PF,((sal+(sal*0.15)+
(sal*0.10))-(sal*0.05)) as Total from emp;
select deptno,count(deptno) from emp group by deptno;
select job,count(job) from emp group by job;
select job,count(job) from emp group by job HAVING count(*)>2;
select deptno,sum(sal) from emp group by deptno;
select deptno,max(sal) from emp group by deptno;
select job,sum(sal) from emp group by job;
select deptno,count(deptno) from emp group by deptno HAVING count(*)>3;
select job,sum(sal) from emp group by job having sum(sal)>5000;
select job,count(empno) from emp group by job having count(job)>3;
or
select job,count(empno) from emp group by job having count(*)>3;
select ename,sal from emp where sal=(select max(sal) from emp);
select empno,ename from emp where job='CLERK' AND sal=(SELECT MAX(SAL) FROM EMP
where job='CLERK');
select ename,sal from emp where sal>(select sal from emp where ename='JONES') AND
SAL>(SELECT SAL FROM EMP WHERE ENAME='SCOTT');
select ename,sal from emp where sal>2975 AND SAL>3000;
SELECT ename,sal,deptno from emp where sal in(select max(sal) from emp group by
deptno);
select ename,sal,job from emp where sal in(select max(sal) from emp group by job);
{select ename from emp where deptno=(select deptno from department where
dname='Accounting');
/*Both Query are same*/
select ename from emp e,department d where dname='Accounting'and e.deptno=d.deptno;
}
select * from department;
{ select ename,deptno from emp where deptno=(select deptno from department where
location='Chicago');
/*Both Query same out Put*/
select ename,e.deptno from emp e,department d where location='Chicago' and
e.deptno=d.deptno;
}
select job,sum(sal) from emp group by job having sum(sal)>(select max(sal) from emp
where job='MANAGER');
select SUM(SAL) from emp;
SELECT ename,sal from emp where deptno=10 and sal>any(select sal from emp where
deptno!=10);
select ename from emp where deptno=10 and sal> all(select sal from emp where
deptno!=10);
select upper(ename) from emp;
select lower(ename) from emp;
select count(empno) from emp;
select ename,length(ename) from emp;
select initcap(ename) from emp;
select length('name') from dual;
select ename ||' '||empno from emp;