# Searching table question

**URL:** <https://www.ruby-forum.com/t/searching-table-question/119332>\
**Category:** Rails\
**Created:** [November 6, 2007, 4:10am UTC](https://www.ruby-forum.com/t/searching-table-question/119332 "2007-11-06T04:10:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![agilehack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d2c977/32.png) [@agilehack](https://www.ruby-forum.com/u/agilehack)\
**Post date:** [November 6, 2007, 4:10am UTC](https://www.ruby-forum.com/t/searching-table-question/119332/1 "2007-11-06T04:10:08Z")

</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:** ![agilehack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d2c977/32.png) [@agilehack](https://www.ruby-forum.com/u/agilehack)\
**Post date:** [November 6, 2007, 4:24am UTC](https://www.ruby-forum.com/t/searching-table-question/119332/2 "2007-11-06T04:24:09Z")

</div>

On Nov 5, 2007, at 9:09 PM, agilehack wrote:

> 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

(inside class ZipCode)

def self.find\_between(zip)  
find(:first, :conditions =\> [‘startzip \<= ? AND endzip \>= ?’,  
zip, zip])  
end

and in your controller

@zip = ZipCode.find\_between(zip)
