# Ambiguous clause error

**URL:** <https://www.ruby-forum.com/t/ambiguous-clause-error/63768>\
**Category:** Rails\
**Created:** [June 19, 2006, 1:51am UTC](https://www.ruby-forum.com/t/ambiguous-clause-error/63768 "2006-06-19T01:51:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasbur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@jasbur](https://www.ruby-forum.com/u/jasbur)\
**Post date:** [June 19, 2006, 1:51am UTC](https://www.ruby-forum.com/t/ambiguous-clause-error/63768/1 "2006-06-19T01:51:46Z")

</div>

I’m trying to query one table to ultimately display the relate info from  
another table. I have 2 tables: “posts” and “numbers”. I’m trying to do  
a query like this:

@numbers = Number.find(:all,  
:conditions =\> [ ‘(user\_id) = :id’,  
{:id =\> @session[‘user’].id}],  
:include =\> :post)

Then display it like this:

\<% for number in @numbers do %\> - \<%= link\_to number.post.title, :controller =\> 'post', :action =\> 'show', :id =\> post %\> Ending: \<%= number.post.end\_date %\>
 \<% end %\>

I’m getting “Column ‘user\_id’ in where clause is ambiguous” From the  
reading I’ve been doing it seems the fact that there is a “user\_id”  
field in both tables might be the issue. How do I work around this? Do I  
have to rename one of the “user\_id” columns, or is there a more elegant  
way of doing this?

---

<div class="post-metadata">

**Author:** ![jasbur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@jasbur](https://www.ruby-forum.com/u/jasbur)\
**Post date:** [June 19, 2006, 4:17am UTC](https://www.ruby-forum.com/t/ambiguous-clause-error/63768/2 "2006-06-19T04:17:36Z")

</div>

Jasbur wrote:

> I’m trying to query one table to ultimately display the relate info from  
> another table. I have 2 tables: “posts” and “numbers”. I’m trying to do  
> a query like this:
> 
> @numbers = Number.find(:all,  
> :conditions =\> [ ‘(user\_id) = :id’,  
> {:id =\> @session[‘user’].id}],  
> :include =\> :post)
> 
> Then display it like this:
> 
> \<% for number in @numbers do %\> - \<%= link\_to number.post.title, :controller =\> 'post', :action =\> 'show', :id =\> post %\> Ending: \<%= number.post.end\_date %\>
> \<% end %\>
> 
> I’m getting “Column ‘user\_id’ in where clause is ambiguous” From the  
> reading I’ve been doing it seems the fact that there is a “user\_id”  
> field in both tables might be the issue. How do I work around this? Do I  
> have to rename one of the “user\_id” columns, or is there a more elegant  
> way of doing this?

When you invlolve more than one table you usually have to specify the  
table name in the sql. Try this:

:conditions =\> [ ‘(numbers.user\_id) = :id’, {:id =\>  
@session[‘user’].id}]

---

<div class="post-metadata">

**Author:** ![jasbur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@jasbur](https://www.ruby-forum.com/u/jasbur)\
**Post date:** [June 19, 2006, 4:29am UTC](https://www.ruby-forum.com/t/ambiguous-clause-error/63768/3 "2006-06-19T04:29:40Z")

</div>

That was it. Actually I just found it in the Agile book right before I  
saw your reply. Thanks for the help.
