deleyd
asked on
SQL join when tables are separated by one or more other tables
Say in an SQL database I have an "Employee" table, which points to a "Person" table, which points to a Person_Name table:
Employee (table)
+------------+-----+ Person (table)
| Field | Key | +------------+-----+ Person_Name (table)
+------------+-----+ | Field | Key | +------------+-----+
| employee_id| PK | +------------+-----+ | Field | Key |
| person_id | FK | --> | person_id | PK | +------------+-----+
+------------+-----+ | name_id | FK | --> | name_id | PK |
+------------+-----+ | people_id | FK |
| name | |
+------------+-----+
What query would list me all employees and their names?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ASKER
Oh I see the problem.
ASKER
OK Thank you I'll use the Image button next time.
Both queries work now.
So I see one pattern is:
SELECT
FROM
JOIN
JOIN
ON
ON
and the other pattern is:
SELECT
FROM
JOIN ... ON ...
JOIN ... ON ...
I suppose both work fine. Thank you for your help!
Both queries work now.
So I see one pattern is:
SELECT
FROM
JOIN
JOIN
ON
ON
and the other pattern is:
SELECT
FROM
JOIN ... ON ...
JOIN ... ON ...
I suppose both work fine. Thank you for your help!
So, name_id wasn't equal :)
Machine is always right ;)
Machine is always right ;)
ASKER
(I have a T-shirt with a human working at the computer. Human thinks, "Stupid computer." Computer thinks, "Stupid human.")
:)
:)
ASKER
Open in new window
Then run the query, which doesn't complain, but also gives me no results. Hmm..,٩(͡๏̯͡๏)۶
(I also removed the people_id from the Person_Name table which served no purpose.)