Discussion Locked

about Oracle

0 helpful
13 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

tell me query of oracle
If we want to reterieve some data from a table whose salary is same take out their names like in Sql we have emp table reterive it from there

13 replies

by hasse mcse/brainbench

Hi!

I don't really know what you mean, and I strongly suggest you get a book on SQL.

Cause what you want to do is something like this.

select * from emp where salary = 20000;

Will return all employers with a $20000 salary.

select * from emp where salary > 60000;

Will return all employers with salary above $60000;

/Hasse

by alekstek

If you just want the name of the employees substitute the * in the previous answer with the appropiate column:
Ex:

select name
from emp
where salary = 20000;

by wchaster

This is a hard question to assertain the meaning ofit. Has this question been submitted for inclusion on the OCP?

If I read this correctly the points missed by the previos two are that a GROUP BY is required to match up employees with the same SALARY. I will add an ORDER BY to make then a little neater.

SELECT name FROM EMP
ORDER BY SALARY
GROUP BY SALARY;

by alekstek

or if you want to retrieve rows from a table that have a common value but you don't know this value:
select name, salary from emp
where salary in
(select salary from emp
group by salary
having count(*) > 1)
order by salary, name;

any wise comments todd ?

by vs

select ename, sal from emp e1
where sal in
(select sal from emp e2
where e1.sal=e2.sal
and e1.ename != e2.ename)
order by sal, ename;

This discussion is closed to new replies.