Why is the id ambiguous even creating an alias?

Asked

Viewed 301 times

1

select deals.id as dealid from funnels
inner join deals on 
deals.funnel_id = funnels.id where id = 3

returns

1052 - Column 'id' in 'Where clause' is ambiguous

My database is Mysql. Why there was ambiguity and I created a nickname for Deals.id?

  • Without you showing the structures of the tables Deals and funnels we could only speculate and not answer clearly. Maybe it is this end ...Where id = 3.

1 answer

5


The error already tells the origin, which is em 'where clause'. The alias, does not change anything in this case, since the WHERE remains as id = 3. You did right in the select and wrong in the where.

The solution, even without alias, would be to use:

select deals.id from funnels
inner join deals on 
deals.funnel_id = funnels.id where deals.id = 3

Of course, since it’s ambiguous, I’m assuming you’re referring to deals.id = 3, if it’s not that, it’ll be funnels.id = 3. Anyway, the problem is in WHERE, as the error points out, so just do the same as you did in the select, specify which table want to use (tabela.id).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.