Examine the structure of the EMPLOYEES and DEPARTMENTS tables:
You want to create a report displaying employee last names, department names, and locations.
Which query should you use to create an equi-join?
A.
SELECT last_name, department_name, location_id
FROM employees , departments ;
B.
SELECT employees.last_name, departments.department_name, departments.location_id
FROM employees e, departments D
WHERE e.department_id =d.department_id;
C.
SELECT e.last_name, d.department_name, d.location_id
FROM employees e, departments D
WHERE manager_id =manager_id;
D.
SELECT e.last_name, d.department_name, d.location_id
FROM employees e, departments D
WHERE e.department_id =d.department_id;
Explanation:
Equijoins are also called simple joins or inner joins. Equijoin involve primary key and foreign key.
Incorrect answer:
Athere is no join
B invalid syntax
Cdoes not involve the join in the primary and foreign key
Refer: Introduction to Oracle9i: SQL, Oracle University Study Guide, 4-8
pls explain why is B wrong
The syntax of B is correct (contrary to the explanation). However both tables have been aliased and the aliases are not used on the SELECT clause.
which in turn originates a “invalid identifier error” (not a syntax error)
If you use an alias for the table name then this alias has to be used to select columns , not the name of the table .