# Retrive data from table

**URL:** <https://www.ruby-forum.com/t/retrive-data-from-table/152188>\
**Category:** Rails\
**Created:** [October 31, 2008, 1:09am UTC](https://www.ruby-forum.com/t/retrive-data-from-table/152188 "2008-10-31T01:09:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xxmithila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ebca7d/32.png) [@xxmithila](https://www.ruby-forum.com/u/xxmithila)\
**Post date:** [October 31, 2008, 1:09am UTC](https://www.ruby-forum.com/t/retrive-data-from-table/152188/1 "2008-10-31T01:09:28Z")

</div>

hi…

how can I retrive data from a specific row of table by giving two  
or more properties of that row?  
examlpe I want to get data which ID = 23 and NAME = “xx” like

thankx

---

<div class="post-metadata">

**Author:** ![xxmithila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ebca7d/32.png) [@xxmithila](https://www.ruby-forum.com/u/xxmithila)\
**Post date:** [October 31, 2008, 1:54am UTC](https://www.ruby-forum.com/t/retrive-data-from-table/152188/2 "2008-10-31T01:54:31Z")

</div>

xxmithila wrote:

> hi…
> 
> how can I retrive data from a specific row of table by giving two  
> or more properties of that row?  
> examlpe I want to get data which ID = 23 and NAME = “xx” like

As long as your table is made up of Models, you can do something like:

@mydata = ModelName.find(‘23’, :conditions =\> “NAME = ‘xxx’” )

HTH

Matt

---

<div class="post-metadata">

**Author:** ![xxmithila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ebca7d/32.png) [@xxmithila](https://www.ruby-forum.com/u/xxmithila)\
**Post date:** [October 31, 2008, 3:13am UTC](https://www.ruby-forum.com/t/retrive-data-from-table/152188/3 "2008-10-31T03:13:33Z")

</div>

Hi,

xxmithila wrote:

> how can I retrive data from a specific row of table  
> by giving two or more properties of that row?  
> examlpe I want to get data which  
> ID = 23 and NAME = “xx” like

If you know the ID, you don’t need anything else. IDs are unique so  
the  
query on the second field just eats cycles with no upside. Assuming  
this  
was just a poorly thought-out example…

# two or more properties are queried, in the most general case, with: Model.find(all, :conditions =\> ["first\_condition =? && second\_condition

?", first\_param, second\_param])

Use the find\_by helpers for more readable / idiomatic code.

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![xxmithila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ebca7d/32.png) [@xxmithila](https://www.ruby-forum.com/u/xxmithila)\
**Post date:** [November 1, 2008, 5:15am UTC](https://www.ruby-forum.com/t/retrive-data-from-table/152188/4 "2008-11-01T05:15:18Z")

</div>

On Sat, Nov 1, 2008 at 6:36 AM, mithila karunarathna  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> > > by giving two or more properties of that row?
> 
> "

thankx friends I got the answer…  
thankx again

---

<div class="post-metadata">

**Author:** ![xxmithila](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ebca7d/32.png) [@xxmithila](https://www.ruby-forum.com/u/xxmithila)\
**Post date:** [November 1, 2008, 2:07am UTC](https://www.ruby-forum.com/t/retrive-data-from-table/152188/5 "2008-11-01T02:07:03Z")

</div>

On Fri, Oct 31, 2008 at 8:42 AM, Bill W.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> If you know the ID, you don’t need anything else. IDs are unique so the  
> Bill
> 
> hoooo

@mydata = ModelName.find(‘23’, :conditions =\> “NAME = ‘xxx’” )  
but this command return error  
"

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.each

"  
I know that code is correct but it return error. What is the reson for  
this?  
xxmithila
