Ambiguous Column Names & Postgres Joins
Wednesday, May 9th, 2007 @ 4:13 am
| PostgreSQL
Most people working with postgres have probably encountered something like this before:
SELECT instrument, priceband, pounds FROM tbl_instruments, tbl_prices WHERE tbl_instruments.priceband=tbl_prices.priceband; ERROR: column reference "priceband" is ambiguous
Although that’s normal behavior according to the SQL standard, and very easy to fix using ‘tbl_instruments.priceband’ in the SELECT, it kind-of doesn’t make sense given that WHERE clause: both tbl_instruments.priceband and tbl_prices.priceband will yeild the same value. I found the following in the Postgres mailing archives (imo, a much neater solution than qualifying the column names):
SELECT instrument, priceband, pounds FROM tbl_instruments JOIN tbl_prices USING (priceband);
Recently

Leave a Reply
You must be logged in to post a comment.