I cannot find this answer anywhere. Apologies in advance... 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. Thanks, TMB -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 30, 2008, at 9:36 PM, Tm Bo wrote:> > I cannot find this answer anywhere. Apologies in advance... > > I need to get the unique values from a particular column and this code > seems to work fine: > > Street.find(:all, :group => :pre_type)Street.find(:all, :select => ''distinct pre_type'') Best. Mike> > > :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. > > Thanks, > > TMB > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 30, 2008, at 10:17 PM, Bill Walton wrote:> > 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 > wantThe :select option of find allows you to specify what columns you want. Best Mike> > returned. Interestingly, it seems the method has disappeared from > the api > spec. Hmm.... Anyway, just Google it. > > HTH, > Bill > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
SQL it is. I was looking too far ;) Thanks, guys. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---