# ActiveRecord: SQL IN operator

**URL:** <https://discuss.rubyonrails.org/t/activerecord-sql-in-operator/32032>\
**Category:** rubyonrails-talk\
**Created:** [July 18, 2008, 11:57am UTC](https://discuss.rubyonrails.org/t/activerecord-sql-in-operator/32032 "2008-07-18T11:57:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [July 18, 2008, 11:57am UTC](https://discuss.rubyonrails.org/t/activerecord-sql-in-operator/32032/1 "2008-07-18T11:57:02Z")

</div>

I want to use an array in the :conditions of an ActiveRecord Find so that a SQL IN statement is created. However, I also want to specify a greater than condition on a timestamp column too. From the Docs: An array may be used in the hash to use the SQL IN operator: &nbsp;&nbsp;Student.find(:all, :conditions =\> { :grade =\> [9,11,12] })

How do I modify this so that it also contains the timestamp condition? :condition =\> ['created\_at \> ?',time]

---

<div class="post-metadata">

**Author:** ![bphogan](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/bphogan/32/4186_2.png) [@bphogan](https://discuss.rubyonrails.org/u/bphogan)\
**Post date:** [July 18, 2008, 2:08pm UTC](https://discuss.rubyonrails.org/t/activerecord-sql-in-operator/32032/2 "2008-07-18T14:08:24Z")

</div>

Hey…

I’ve been doing Rails for a while and have never adopted the hash syntax for conditions. Someone else might be able to help you with that, but I know this will work:

Student.find :all, :conditions = \>[“grade in (?) and created\_at \> ?”, [9,11,12], time]

---

<div class="post-metadata">

**Author:** ![rab](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/rab/32/710_2.png) [@rab](https://discuss.rubyonrails.org/u/rab)\
**Post date:** [July 18, 2008, 2:26pm UTC](https://discuss.rubyonrails.org/t/activerecord-sql-in-operator/32032/3 "2008-07-18T14:26:33Z")

</div>

> Hey…

> I’ve been doing Rails for a while and have never adopted the hash syntax for conditions. Someone else might be able to help you with that, but I know this will work:

> Student.find :all, :conditions = \>[“grade in (?) and created\_at \> ?”, [9,11,12], time]

Yes, that’s it. If you like the Hash form for conditions, you might like DataMapper where the same query would look like:

Student.all(:grade =\> [9,11,12], :created\_at.gt =\> time)

[http://datamapper.org/](http://datamapper.org/)

-Rob
