Informatics Practices
Examine the structure of the EMPL and DEPT tables:
Table : EMPL
| Column name | Data type | Remarks |
|---|---|---|
| EMPLOYEE_ID | NUMBER | NOT NULL, Primary Key |
| EMP_NAME | VARCHAR(30) | |
| JOB_ID | VARCHAR(20) | |
| SALARY | NUMBER | |
| MGR_ID | NUMBER | References EMPLOYEE_ID COLUMN |
| DEPARTMENT ID | NUMBER | Foreign key to DEPARTMENT ID column of the DEPT table |
Table : DEPT
| Column name | Data type | Remarks |
|---|---|---|
| DEPARTMENT_ID | NUMBER | NOT NULL, Primary Key |
| DEPARTMENT_NAME | VARCHAR(30) | |
| MGR_ID | NUMBER | References 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
3 Likes
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
2 Likes
Related Questions
What is the correct statement for describing the EXCEPT operation ?
- It excludes all the rows present in both the queries
- It includes the rows of the second query but excludes the results of the first query
- It includes the rows of the first query but excludes the results of the second query
- It includes all the rows of both queries but removes duplicates
What is the other name of MINUS operator?
- UNION
- UNION ALL
- EXCEPT
- INTERSECT
Fill in the blanks:
An SQL _________ clause combines records from two or more tables in a database.
Fill in the blanks:
An _________ is a specific type of join that uses only equality comparisons in the join-condition.