I have an emp
table, with schema and some initial values like below:
emp_id | name | last_name | role_id
--------+------+-----------+---------
1 | hell | bell | 1
2 | well | tell | 2
(2 rows)
And another role
table, which emp
table has referenced on role_id
.
Below is the role
table:
role_id | role_name
---------+-----------
1 | tech
2 | op
3 | dev
(3 rows)
I was just playing around, and wrote the below query, which I suppose don’t make much sense.
SELECT emp.name, role.role_name, emp.emp_id
FROM emp
INNER JOIN role
ON emp.role_id = (
SELECT role_id from role WHERE role_name = 'tech'
);
It worked and returned this result:
name | role_name | emp_id
------+-----------+--------
hell | tech | 1
hell | op | 1
hell | dev | 1
(3 rows)
I would like to know why I’got this result and how it worked?