I have a query like this:
SELECT *
FROM table1 ref1,
table1 ref2,
table2 ref3,
table2 ref4,
table3
WHERE ref3.a = ref1.b ,
ref4.a = ref2.b ,
ref3.c = f,
ref4.c = d
and it works great, it gives me 1 record with all the columns I want.
Two of these columns have the same name but the latter one gets intuitively the extension _1, so the first column with that name has the name frubberducks
and the second one has the name frubberducks_1
, and that's great. I need a query that only gives me these two columns so I tried:
SELECT frubberducks
FROM table1 ref1,
table1 ref2,
table2 ref3,
table2 ref4,
table3
WHERE ref3.a = ref1.b ,
ref4.a = ref2.b ,
ref3.c = f ,
ref4.c = d
and I get the error:
ORA-00918: column ambiguously defined
Whats the best way of doing this?
The best way to do that is using table aliases and column aliases as below
for one column:
for two columns with the same name:
for two columns with the same name and with column aliases: