Unique column values

Hi Tm,

Tm Bo wrote:

I need to get the unique values from a particular column and this code seems to work fine:

Street.find(:all, :group => :pre_type)

:pre_type being the ONLY column I need results for. the above code returns the data from all the other columns for each particular row, which is more than I need.

The find above should return a row for each unique value of the 'pre_type' column. If you only want the values for the column itself, you'll probably need to do a select_by_sql and specify that that's the only data you want returned. Interestingly, it seems the method has disappeared from the api spec. Hmm.... Anyway, just Google it.

HTH, Bill

Hi Tm,

Tm Bo wrote:

I need to get the unique values from a particular column and this code seems to work fine:

Street.find(:all, :group => :pre_type)

:pre_type being the ONLY column I need results for. the above code returns the data from all the other columns for each particular row, which is more than I need.

The find above should return a row for each unique value of the
'pre_type' column. If you only want the values for the column itself, you'll
probably need to do a select_by_sql and specify that that's the only data you
want

The :select option of find allows you to specify what columns you want.

Best Mike