Not equal to query

Hi Champs,

Hanging out with a problem.. I can find out the name of cities with City.find(:all).. I can find out the Bangalore city with City.find_by_name("Bangalore"). But what query i have to write to find the name of all cities except "Bangalore" ?

I tried this but of no use .. City.find(:all, :conditions => { :name != "Bangalore" })

Can you people push me into the right direction.

- Cheers

Hemant Bhargava wrote:

Hi Champs,

Hanging out with a problem.. I can find out the name of cities with City.find(:all).. I can find out the Bangalore city with City.find_by_name("Bangalore"). But what query i have to write to find the name of all cities except "Bangalore" ?

I tried this but of no use .. City.find(:all, :conditions => { :name != "Bangalore" })

Can you people push me into the right direction.

- Cheers

Try below syntax.

City.find(:all, :conditions => [ "name != 'Bangalore'"] )

Thanks Brijesh Shah

I am having Bangalore in an variable. I mean lets suppose selected_city. Then i tried this:- City.find(:all, :conditions => [ "name != selected_city" ]

Nopes this is not working ..

Brijesh Shah wrote:

Hemant Bhargava wrote:

I am having Bangalore in an variable. I mean lets suppose selected_city. Then i tried this:- City.find(:all, :conditions => [ "name != selected_city" ]

Nopes this is not working ..

Then try with this...

City.find(:all, :conditions => [ "name != ?",selected_city ]

selected_city must be variable.

Thanks Brijesh Shah

I am having Bangalore in an variable. I mean lets suppose selected_city.

Then i tried this:-

City.find(:all, :conditions => [ “name != selected_city” ]

Try the following:

City.find( :all, :conditions => [ “name != selected_city” ] )

or

City.find(:all, :conditions => [ “name != ?”, selected_city ] )

-Conrad

Thanks Dude .. Worked ..

Brijesh Shah wrote:

Thanks conrad,

2nd worked .. :slight_smile:

Conrad Taylor wrote: