Professional Documents
Culture Documents
Paghunasan Prelim
Paghunasan Prelim
The following abstract summary represents the notation used for selecting data from
more than one table:
SELECT table1.column, table2.column, ...
FROM table1, table2, ...
WHERE table1.columnX = table2.columnY
Exercises:
1. Write a query to display the name, department number, and the department name
for all employees.
ANSWER:
SELECT dname,deptno
FROM DEPT;
2. Create a unique listing of all jobs with their respective locations that are
in department30.
ANSWER:
SELECT loc,job FROM emp, dept
WHERE dept.deptno LIKE '30';
3. Write a query to display the employee name, department name, and location of
all employees who earn a commission.
ANSWER:
SELECT ename,dname,loc,comm
FROM emp, dept;
4. Write a query to display the name, job, department number, and department name
for all employees who work in Dallas.
ANSWER:
SELECT ename, job, deptno, depid
FROM emp
WHERE city = 'Dallas';
5. Display the employee name and employee number along with their manager’s name and
manager number. Label the columns Employee, Emp#, Manager, and Mgr#, respectively.
ANSWER:
SELECT e.ename AS Employee, e.empno AS "Emp#", m.ename AS Manager,
m.empno AS "Mgr#"
FROM emp e
LEFT JOIN emp m ON e.mgr = m.empno:
6. Modify your query from 5 to display all employees including also those who do not
have a manager.
ANSWER:
7. Create a query that will display the name, job, department name, salary, and grade for
all employees.
ANSWER:
SELECT ename, job, dname, esal,
sgrade
FROM emp, dept, salgrade
WHERE emp.deptno = dept.deptno;