# searching table question

**URL:** <https://discuss.rubyonrails.org/t/searching-table-question/20102>\
**Category:** rubyonrails-talk\
**Created:** [November 6, 2007, 3:09am UTC](https://discuss.rubyonrails.org/t/searching-table-question/20102 "2007-11-06T03:09:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![agilehack](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@agilehack](https://discuss.rubyonrails.org/u/agilehack)\
**Post date:** [November 6, 2007, 3:09am UTC](https://discuss.rubyonrails.org/t/searching-table-question/20102/1 "2007-11-06T03:09:26Z")

</div>

this confuses me...

@zip = ZipCode.find(zip)

where @zip is the first 3 digits of a zipcode the table is zipcodes the model zipcode

so i understand @zip = Zipcode.find(zip) is attempting to look for zip in the zipcodes table via the model zipcode

however i need to compare my 3 digit zip (@zip) againt two columns in the table column 1 - zipstart column 2 - endzip

i need to find the row that my @zip falls inside the values of those two columns, so i believe this line of code is too simple

example might be @zip = 034 startzip = 032 and endzip =037 in the table i need to identify that row

can anyone help?

---

<div class="post-metadata">

**Author:** ![George\_Bailey](https://avatars.discourse-cdn.com/v4/letter/g/9d8465/32.png) [@George\_Bailey](https://discuss.rubyonrails.org/u/George_Bailey)\
**Post date:** [November 6, 2007, 3:23am UTC](https://discuss.rubyonrails.org/t/searching-table-question/20102/2 "2007-11-06T03:23:30Z")

</div>

(inside class ZipCode)

&nbsp;&nbsp;&nbsp;def self.find\_between(zip) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;find(:first, :conditions =\> ['startzip \<= ? AND endzip \>= ?', zip, zip]) &nbsp;&nbsp;&nbsp;end

and in your controller

@zip = ZipCode.find\_between(zip)
