Tom
Tom

Reputation: 81

Using a self join and a join with a third table in one query

I would like to self join on a table and then join this to a third table...below is my attempt but I get a 904 error on line 4 "a.employee_t.employeeid". Is this possible and what syntax would I use?

SELECT a.employeename, b.employeename
FROM employee_t a, employee_t b
JOIN employeeskills_t ON 
a.employee_t.employeeid=employeeskills_t.employeeid;

EDIT: I should have hesitated before posting this because my code was very nonsensical...I'll post below with proper syntax (no 904 errors)

SELECT a.employeename, b.employeename, employeeskills_t.skillid
FROM employee_t a
JOIN employee_t b ON a.employeeid=b.employeeid
JOIN employeeskills_t ON a.employeeid=employeeskills_t.employeeid;

I'm using Oracle Database version 12.2.0.1.0

Upvotes: 1

Views: 421

Answers (3)

W_O_L_F
W_O_L_F

Reputation: 1486

A bit of guesswork here.. maybe this is what you are looking for? I assume you want to expand this query it is not making much sence right now.

SELECT a.employeename, b.employeename
FROM employee_t a
JOIN employee_t b on a.employeeid= b.employeeid
JOIN employeeskills_t c ON a.employeeid=c.employeeid;

Upvotes: 3

randomDude1001
randomDude1001

Reputation: 169

Your query should be something like this:

SELECT a.employeename, b.employeename
FROM employee_t a
JOIN employee_t b ON
b.employeeid = a.employeeid (YOUR JOIN CONDITION)
JOIN employeeskills_t ON
employeeskills_t.employeeid = a.employeeid;

Note that I changed the Join condition a.employee_t.employeeid=employeeskills_t.employeeid because you used the table alias as well as the table name.

Upvotes: 0

dMazay
dMazay

Reputation: 65

No, you can not use different syntaxis. employee_t a, employee_t b must be joined via JOIN

Upvotes: 0

Related Questions