# Camparing table and instance of another table

**URL:** <https://www.ruby-forum.com/t/camparing-table-and-instance-of-another-table/132751>\
**Category:** Rails\
**Created:** [March 24, 2008, 12:52pm UTC](https://www.ruby-forum.com/t/camparing-table-and-instance-of-another-table/132751 "2008-03-24T12:52:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![katsuo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@katsuo](https://www.ruby-forum.com/u/katsuo)\
**Post date:** [March 24, 2008, 12:52pm UTC](https://www.ruby-forum.com/t/camparing-table-and-instance-of-another-table/132751/1 "2008-03-24T12:52:52Z")

</div>

Hi, I did the following to compare two tables, products and orders using  
LEFT OUTER JOIN. It came out fine.

However, I am not sure how to do the similar join if the products are an  
array. For example, there is another table called brands having the  
relationships - brand has\_many:products and products belongs\_to:brand.  
@brands = brand.find(params[:id])picks up particular brand and all the  
products from that brand.

On the view, I would like to display list of products from one brand and  
do LEFT OUTER JOIN with orders table. I would truly appreciate the  
advise on how to modify the following to accomplish this task or at  
least guide me to the right direction.

Table products  
id  
name  
brand\_id

Table orders  
id  
product\_id  
customer\_name

product has\_many: orders  
order belongs\_to: product

Def list  
@products = Product.find(:all)  
@orders = Order.find(:all)  
@compares = Product.connection.select\_all(“SELECT products.id AS  
prod,products.name AS name, orders.product\_id AS ord FROM  
products LEFT OUTER JOIN orders ON products.id = orders.product\_id”)  
end
