# Condition LIKE with or for autocomplete

**URL:** <https://www.ruby-forum.com/t/condition-like-with-or-for-autocomplete/156725>\
**Category:** Rails\
**Created:** [January 2, 2009, 12:13am UTC](https://www.ruby-forum.com/t/condition-like-with-or-for-autocomplete/156725 "2009-01-02T00:13:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pipex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pipex](https://www.ruby-forum.com/u/pipex)\
**Post date:** [January 2, 2009, 12:13am UTC](https://www.ruby-forum.com/t/condition-like-with-or-for-autocomplete/156725/1 "2009-01-02T00:13:28Z")

</div>

Hello!

I need some help. I am doing an auto complete that hast to find result  
from  
a mysql database of some people if the text written in the text box  
matches  
the name or last name. It works if i only want to find matches with the  
name  
or indepently the secon name but not with a or of both.  
I have this

@inscritos = Inscrito.find(:all,  
:conditions =\> [“LOWER(nombre) LIKE ?”,  
‘%’ + params[:familiar][“0”].downcase + ‘%’ ],  
:order =\> ‘apellido ASC’,  
:limit =\> 8)

this works fine but then i want something like this

## @inscritos = Inscrito.find(:all, :conditions =\> [“LOWER(nombre) OR LOWER(apellido) LIKE ?”, ‘%’ + params[:familiar][“0”].downcase + ‘%’ ], :order =\> ‘apellido ASC’, :limit =\> 8)

Felipe V. Contesse  
IngenierÃ­a Civil Industrial UC

---

<div class="post-metadata">

**Author:** ![pipex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pipex](https://www.ruby-forum.com/u/pipex)\
**Post date:** [January 2, 2009, 1:07am UTC](https://www.ruby-forum.com/t/condition-like-with-or-for-autocomplete/156725/2 "2009-01-02T01:07:19Z")

</div>

Shouldn’t it be

@inscritos = Inscrito.find(:all,  
:conditions =\> [“LOWER(nombre) LIKE ? OR LOWER(apellido) LIKE  
?”,  
‘%’ + params[:familiar][“0”].downcase + ‘%’ ],  
‘%’ + params[:familiar][“0”].downcase + ‘%’ ],  
:order =\> ‘apellido ASC’,  
:limit =\> 8)

otherwise you are saying ‘LOWER(nombre) is true or LOWER(apellido) LIKE  
blah’

Cheers  
Simon

On Fri, 02 Jan 2009 08:12:32 +0900, Felipe V.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![pipex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pipex](https://www.ruby-forum.com/u/pipex)\
**Post date:** [January 2, 2009, 1:07am UTC](https://www.ruby-forum.com/t/condition-like-with-or-for-autocomplete/156725/3 "2009-01-02T01:07:54Z")

</div>

On Thu, Jan 1, 2009 at 3:12 PM, Felipe V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I need some help. I am doing an auto complete that hast to find result from  
> a mysql database of some people if the text written in the text box matches  
> the name or last name. It works if i only want to find matches with the name  
> or indepently the secon name but not with a or of both.

> @inscritos = Inscrito.find(:all,  
> :conditions =\> [“LOWER(nombre) OR LOWER(apellido) LIKE ?”,

I would think that would work if you enclosed your arguments in  
parens, e.g.

(LOWER(nombre) OR LOWER(apellido)) LIKE ?

or alternatively

LOWER(nombre) LIKE ? OR LOWER(apellido) LIKE ?

## FWIW,

Hassan S. ------------------------ removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![pipex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pipex](https://www.ruby-forum.com/u/pipex)\
**Post date:** [January 2, 2009, 5:00pm UTC](https://www.ruby-forum.com/t/condition-like-with-or-for-autocomplete/156725/4 "2009-01-02T17:00:57Z")

</div>

I made a concatenation of nombre apellido and then made the search that  
worked great.  
Thank for your help

–  
Felipe V. Contesse  
IngenierÃ­a Civil Industrial UC
