Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Joining 2 Views

Author  Topic 

cableca
Starting Member

6 Posts

Posted - 2008-02-27 : 12:08:10
Hi, I am new to sql and I am trying to join 2 views using MySQL Query Browser. Here is my query and the issues I am having.

SELECT book_month, region_book, product_group as base_prod_group, cnt as base_cnt FROM collections.v_nonpay_trend_base a
join collections.v_nonpay_trend_npdata b
on (a.book_month=b.disc_check_in_month and a.region_book=b.region and a.base_prod_group=b.product_group)

Error - "Column 'product_group' in field list is ambiguous" and "Column 'cnt' in field list is ambiguous"

Both views have columns named 'product_group' and 'cnt'

Can someone please let me know what I am doing wrong?

Thanks!!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-27 : 12:17:52
You must fully qualify the columns to tell parser from where it should take values. so change like this:-

SELECT book_month, region_book, {a/b}.product_group as base_prod_group, {a/b}.cnt as base_cnt FROM collections.v_nonpay_trend_base a
join collections.v_nonpay_trend_npdata b
on (a.book_month=b.disc_check_in_month and a.region_book=b.region and a.base_prod_group=b.product_group)


use either a or b as alias in code in blue.
Go to Top of Page

cableca
Starting Member

6 Posts

Posted - 2008-02-27 : 14:04:23
Thank you! it totally worked!
Go to Top of Page
   

- Advertisement -