KnowledgeBoat Logo

Informatics Practices

Examine the structure of the EMPL and DEPT tables:

Table : EMPL

Column nameData typeRemarks
EMPLOYEE_IDNUMBERNOT NULL, Primary Key
EMP_NAMEVARCHAR(30)
JOB_IDVARCHAR(20)
SALARYNUMBER
MGR_IDNUMBERReferences EMPLOYEE_ID COLUMN
DEPARTMENT IDNUMBERForeign key to DEPARTMENT ID column of the DEPT table

Table : DEPT

Column nameData typeRemarks
DEPARTMENT_IDNUMBERNOT NULL, Primary Key
DEPARTMENT_NAMEVARCHAR(30)
MGR_IDNUMBERReferences MGR_ID column of the EMPL table

Evaluate this SQL statement :

SELECT employee_id, e.department_id, department_ name, salary 
FROM EMPL e, DEPT d
WHERE e.department_id = d.department_id;

Which SQL statement is equivalent to the above SQL statement ?

(a)

SELECT employee_id, department_id, department_name, salary 
FROM EMPL
WHERE department_id MATCHES department_id of DEPT;

(b)

SELECT employee_id, department_id, department_name,salary 
FROM EMPL
NATURAL JOIN DEPT;

(c)

SELECT employee_id, d.department_id, department_name,salary
FROM EMPL e 
JOIN DEPT d 
ON e.department_id = d.department_id;

(d)

SELECT employee_id, department_id, department_name,salary
FROM EMPL 
JOIN DEPT 
USING (e. department _id, d.department_id);

SQL Joins & Grouping

1 Like

Answer

SELECT employee_id, d.department_id, department_name, salary
FROM EMPL e 
JOIN DEPT d 
ON e.department_id = d.department_id;

Reason — Both SQL statements are equivalent as they perform an inner join between the EMPL and DEPT tables based on their department_id columns. The first SQL statement uses implicit join syntax with a WHERE clause to specify the join condition, while the second SQL statement uses explicit join syntax with the JOIN keyword and ON clause.

Answered By

3 Likes


Related Questions