Chapter 7 Application Flashcards

1
Q

Code a query with subquery to project employee data for all with salary less than the average salary for all employees.

A

Select * from employee where salary < (select avg(salary) from employee);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Prepare a nested query that projects employee name for all located in DALLAS (i.e. subquery to find, not “hard code”, the department number).

A

Select ename from employee where deptno = (select deptno from department where location = ‘DALLAS’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Use the IN operator in a query with subquery to project department names for those departments with an employee earning more than $3000.

A

select dName, deptno from department where deptno IN (select deptno from employee where salary > 3000);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Use the ANY keyword in a query with subquery to show those departments with an employee earning less than $2000.*

A

select distinct(deptno) from employee where salary < ANY (select salary from employee where salary < 2000);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Prepare a correlated subquery to project employee name for all employees in that department located in DALLAS.

A

select ename from employee where deptno = (select deptno from department where location = ‘DALLAS’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Do a correlated subquery with the EXISTS operator to list the names of departments that have employees.

A

select dName from department where deptno IN (select deptno from employee where ename IN (select ename from employee));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Do a correlated subquery with the NOT EXISTS operator to list the names of departments that do not have employees.

A

select dName from department where NOT EXISTS (select deptno from employee where deptno = department.deptno);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Prepare a nested query to project department name for the department having the lowest paid employee.

A

select dName from department where deptno = (select deptno from employee where salary = (select MIN(salary) from employee));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly