# Query from tables that have one column name in common

**URL:** <https://www.ruby-forum.com/t/query-from-tables-that-have-one-column-name-in-common/165697>\
**Category:** Rails\
**Created:** [April 16, 2009, 3:06pm UTC](https://www.ruby-forum.com/t/query-from-tables-that-have-one-column-name-in-common/165697 "2009-04-16T15:06:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c5a1d2/32.png) [@mikam](https://www.ruby-forum.com/u/mikam)\
**Post date:** [April 16, 2009, 3:06pm UTC](https://www.ruby-forum.com/t/query-from-tables-that-have-one-column-name-in-common/165697/1 "2009-04-16T15:06:10Z")

</div>

Hi!  
I have a situation where I need to get data from multiple tables and two  
of them share one column name. In table “order\_items” and “products”  
there is column “cost\_price”. Now when I do the following query I get my  
item.cost\_price to receive its value from the “product” table, but I  
would like to have it read from “order\_items” table. Is there a way to  
limit the joins to take only some specific columns from the “product”  
table? Or is there a way to prevent “products” table column “cost\_price”  
to override the data received from the other table? Exclude it from the  
query some way?

order\_items = OrderItem.between(100.years.ago,  
100.years.from\_now).find(:all, :joins =\> [{:order =\> :user}, :product],  
:conditions =\> filters\_for\_business\_unit)

@items = order\_items.map do |item|

total\_cost\_price = item.cost\_price

-Mika
