Reputation: 289
I have two tables like so:
Table Name: Foo
Foo Columns: (ID, UNIQUE_ID, NAME)
Table Name: Bar
Bar Columns (FOO_ID, UNIQUE_ID, NAME)
I basically want all bars
that belong to a particular foo
, and the result should be two columns UNIQUE_ID
and NAME
of each bar
.
My SQL looks like so:
SELECT UNIQUE_ID, NAME FROM BAR B INNER JOIN FOO F ON F.ID = B.FOO_ID WHERE F.UNIQUE_ID = 123
I provide the UNIQUE_ID
. The problem is that both tables have a UNIQUE_ID
column, so I receive the following error: SQL Error: ambiguous column name: UNIQUE_ID
. How do I add in alias for the column in Foo
so that my result of UNIQUE_ID
and NAME
contains the unique ID of Bar
? I don't want an alias for the UNIQUE_ID
column in Bar
.. the result should have the actual column name.
Upvotes: 0
Views: 46
Reputation: 1271051
Is this what you want?
SELECT B.UNIQUE_ID, B.NAME
FROM BAR B INNER JOIN
FOO F
ON F.ID = B.FOO_ID
WHERE F.UNIQUE_ID = 123
You should qualify all column references in the query.
Upvotes: 1