rails 3, active record: any way to tell how many unique values match a "x LIKE ?" query
Posted
by
jpwynn
on Stack Overflow
See other posts from Stack Overflow
or by jpwynn
Published on 2011-03-20T07:59:24Z
Indexed on
2011/03/20
8:09 UTC
Read the original article
Hit count: 206
I have a query to find all the phone numbers that match a partial expression such as "ends with 234"
@matchingphones = Calls.find :all,
:conditions => [ "(thephonenumber LIKE ?)", "%234"]
The same phone number might be in the database several times, and so might be returned multiple times by this query if it matches.
What I need is to know is UNIQUE phone numbers the query returns.
For example if the database contains
000-111-1234 *
000-111-3333
000-111-2234 *
000-111-1234 *
000-111-4444
the existing query will return the 3 records marked with * (eg returns one phone number -1234 twice since it's in the database twice)
what I need is a query that returns just once instance of each match, in this case
000-111-1234 *
000-111-2234 *
© Stack Overflow or respective owner