cancel
Showing results for 
Search instead for 
Did you mean: 

Aliasing query on joins

Former Member
2,059

Simple Query

select * from c_master join e_master;

[No Problem]

BUT

select * from c_master c join e_master e;

[Could not execute statement. There is more than one way to join 'c' to 'e' SQLCODE=-147, ODBC 3 State="42000"]

Why is this?

Accepted Solutions (1)

Accepted Solutions (1)

VolkerBarth
Contributor
0 Kudos

This doc page might give a clue:

As you are using JOIN without an explicit ON condition and without a further JOIN specifier, you are using a KEY JOIN. And this is somewhat dependent on the role name of the FK relationship, which seems to depend on the name of the table. I could imagine (but that's a guess) that using an ALIAS somewhat "disturbs" that search here - but that would only hold if there are more than one FKs between c_master and e_master, and one of them is named after the parent table - that would be the one used when not using an ALIAS).

FWIW, I regurlary use KEY JOINs with tables with ALIASed names and have never run into that issue. IMHO, KEY JOINs only fail (as expected) when there are more than 2 FK relationships (and in our cases, if so, they are both named differently than the parent table itself).

Answers (0)