Does somebody know why this works with both table alias "x"?
Select x.company_name
,x.employee_name
FROM company x
JOIN employee x ON x.company_id = 5
I know that the JOIN with id 5 makes no sense...
Thanks for the lesson!
Does somebody know why this works with both table alias "x"?
Select x.company_name
,x.employee_name
FROM company x
JOIN employee x ON x.company_id = 5
I know that the JOIN with id 5 makes no sense...
Thanks for the lesson!
I'd lay money on "Oracle bug" - Of all the things that've most held me back from adopting the ANSI JOIN syntax, it's been Oracle's painfully egregious and bug-laden implementation thereof. That said, "Failure to catch a syntax error" is pretty minor, and Oracle has, as far as I can tell, largely cleaned up their act.
The first two queries below are equivalent. In the
ON
clause of the join the table aliasx
only refers to the last table to use that alias so only theemployee
table is restricted.In the
SELECT
andWHERE
expressions thex
alias refers to both tables - so, where the column names are unique then they can be successfully referenced but where there are identical column names then oracle raises anORA-00918: column ambiguously defined
exception (as happens in query 3 if the comment is removed).I can't find any documentation on this but it looks very like a bug.
SQL Fiddle
Oracle 11g R2 Schema Setup:
Query 1:
Results:
Query 2:
Results:
Query 3:
Results: