# Find\_by

**URL:** <https://www.ruby-forum.com/t/find-by/185157>\
**Category:** Rails\
**Created:** [March 15, 2010, 11:48am UTC](https://www.ruby-forum.com/t/find-by/185157 "2010-03-15T11:48:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_I\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/839c29/32.png) [@M\_I\_R](https://www.ruby-forum.com/u/M_I_R)\
**Post date:** [March 15, 2010, 11:48am UTC](https://www.ruby-forum.com/t/find-by/185157/1 "2010-03-15T11:48:27Z")

</div>

hi,  
I have to retrieve data from table with two conditions using a actully  
the following query

select \* from abc where id=1 and type = ‘a’

how will i do if:

find\_by\_id(id) \>\>\>\>\> how will i use for multiple conditions

---

<div class="post-metadata">

**Author:** ![M\_I\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/839c29/32.png) [@M\_I\_R](https://www.ruby-forum.com/u/M_I_R)\
**Post date:** [March 15, 2010, 11:57am UTC](https://www.ruby-forum.com/t/find-by/185157/2 "2010-03-15T11:57:49Z")

</div>

On 15 March 2010 10:47, M I R [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> select \* from abc where id=1 and type = ‘a’
> 
> how will i do if:
> 
> find\_by\_id(id) \>\>\>\>\> how will i use for multiple conditions

Model.all(:conditions =\> [“id = ? AND type = ?”, id, type])

> **[ActiveRecord::Base](https://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002263)**
>
> Active Record Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked.

---

<div class="post-metadata">

**Author:** ![M\_I\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/839c29/32.png) [@M\_I\_R](https://www.ruby-forum.com/u/M_I_R)\
**Post date:** [March 15, 2010, 12:07pm UTC](https://www.ruby-forum.com/t/find-by/185157/3 "2010-03-15T12:07:11Z")

</div>

i have already did in this method i was looking for a function like  
that.  
Thanks.

---

<div class="post-metadata">

**Author:** ![M\_I\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/839c29/32.png) [@M\_I\_R](https://www.ruby-forum.com/u/M_I_R)\
**Post date:** [March 15, 2010, 12:21pm UTC](https://www.ruby-forum.com/t/find-by/185157/4 "2010-03-15T12:21:15Z")

</div>

find\_by\_xxx\_and\_yyy\_and\_zzz (with as many conditions as you want)  
how will i put the values against xxx, yyy and zzz,  
i am new to rails so please give me an explicit example.

On Mar 15, 4:06 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![M\_I\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/839c29/32.png) [@M\_I\_R](https://www.ruby-forum.com/u/M_I_R)\
**Post date:** [March 15, 2010, 12:09pm UTC](https://www.ruby-forum.com/t/find-by/185157/5 "2010-03-15T12:09:32Z")

</div>

On Mar 15, 10:47 am, M I R [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> hi,  
> I have to retrieve data from table with two conditions using a actully  
> the following query
> 
> select \* from abc where id=1 and type = ‘a’
> 
> how will i do if:
> 
> find\_by\_id(id) \>\>\>\>\> how will i use for multiple conditions

you can do find\_by\_xxx\_and\_yyy\_and\_zzz (with as many conditions as you  
want)

Fred

---

<div class="post-metadata">

**Author:** ![M\_I\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/839c29/32.png) [@M\_I\_R](https://www.ruby-forum.com/u/M_I_R)\
**Post date:** [March 16, 2010, 12:48pm UTC](https://www.ruby-forum.com/t/find-by/185157/6 "2010-03-16T12:48:02Z")

</div>

On Mon, Mar 15, 2010 at 4:17 PM, M I R [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> –  
> You received this message because you are subscribed to the Google G.  
> “Ruby on Rails: Talk” group.  
> To post to this group, send email to removed\_email\_address@domain.invalid.  
> To unsubscribe from this group, send email to  
> removed\_email\_address@domain.invalid[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> .  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

Hello dear please check it this :

> Abc.find(:all, :conditions =\> “id = 1” && “type = a”, :order =\> “created\_on  
> DESC”)

thanks : Surender Pal Pareek

---

<div class="post-metadata">

**Author:** ![M\_I\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/839c29/32.png) [@M\_I\_R](https://www.ruby-forum.com/u/M_I_R)\
**Post date:** [March 15, 2010, 12:25pm UTC](https://www.ruby-forum.com/t/find-by/185157/7 "2010-03-15T12:25:56Z")

</div>

On Mar 15, 11:20 am, M I R [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> find\_by\_xxx\_and\_yyy\_and\_zzz (with as many conditions as you want)  
> how will i put the values against xxx, yyy and zzz,  
> i am new to rails so please give me an explicit example.

There are some examples on

> **[ActiveRecord::Base](https://api.rubyonrails.org/classes/ActiveRecord/Base.html)**
>
> Active Record Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked.

Fred
