Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I can't get these queries?

Status
Not open for further replies.

Drew37

Programmer
Feb 19, 2002
2
0
0
US
How come I get no rows selected for this query?
6-1 Write a query to display the employeee name and hire date for all employees in the same department as Blake. Exclude Blake.

select ename, hiredate
from emp
Where job =
(select job
from emp
where ename In ('Blake'));

6-2 Create a query to display the employee number and name for all employees who earn more than the average salary. Sort the results in descending order of salary.

Select empno, ename
from emp
where sal >

(select avg(sal)
from emp);

6-3 Write a query that will display the employee number and name for all employees who work in a department with any employee whose name contains a T. Save your SQL statement in a file.
select empno, ename
from emp
where ename Like '%T%';


6-4 Display the employee name, department number and job title for all employees whose department location is Dallas.
select ename, deptno, job
from emp
where dept.deptno=emp.deptno
and dept.loc =
(select loc
from dept
where loc = 'Dallas');


6-5 Display the employee name and salary of all employees who report to King.

select ename, sal
from emp
where MGr =
(select mgr
from emp
where MGR In ('King'));

6-6 Display the employee name and salary of all employees who report to King.

select deptno, ename, job
from emp
where job =
(select job
from emp
where job In('Sales Department'));
 


6-1 Write a query to display the employeee name and hire date
or all employees in the same department as Blake. Exclude
Blake.

select ename, hiredate
from emp
Where deptno in -- May be Blake not in one depart
(select deptno
from emp
where ename In ('BLAKE'))
and ename != 'BLAKE';

6-2 Create a query to display the employee number and name
for all employees who earn more than the average salary. Sort
the results in descending order of salary.

Select empno, ename
from emp
where sal >
(select avg(sal)
from emp)
order by sal desc;

6-3 Write a query that will display the employee number and
name for all employees who work in a department with any
employee whose name contains a T. Save your SQL statement in a file.

select empno, ename
from emp
where depno in (select depno from emp
where ename Like '%T%');


6-4 Display the employee name, department number and job title
for all employees whose department location is Dallas.

select ename, deptno, job
from emp
where emp.deptno in
(select deptno
from dept
where upper(loc) = upper('Dallas'));
/* "Dallas" is same like DALLAS" */

or
select emp.ename, emp.deptno, emp.job
from emp,dept
where emp.deptno = dept.deptno
and upper(dept.loc) = upper('Dallas');


6-5 Display the employee name and salary of all employees who
report to King.

select ename, sal
from emp
where MGr =
(select empno
from emp
where ename In ('KING'));
6-6 Display the employee name and salary of all
????????? employees who
report to King. (same 6-5) ?????????

????????????????????????????????

Before write your selects check table: UPPER/LOW CASE
etc
select * from emp; select * from dept;

 
select ename, sal
from emp
where MGr IN -- There might be more than one King
(select empno
from emp
where ename = UPPER('KING'));
 
MY goof!

select ename, sal
from emp
where MGr IN -- There might be more than one King
(select empno
from emp
where UPPER(ename) = 'KING');
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top