On Oct 31, 12:54 ¨Âí¬ äëíäßîéåìóåî ¼ä®®®Àãíóãíó®ãïí÷òïôåº > Thanks for any help and suggestions. ¨Â§í èáöéîç ôòïõâìåó ÷éôè ôè> following not working. ¨Âçåîåòáôå¢íéóöáìõæïºÏÃÒÁÃéî > OCRACR = :OCRACR..." error. > > slct = "OCRACR = :OCRACR and MSG = :MSG and KEYCODE = :KEYCODE and > VERSION = :VERSION and DEPTH = :DEPTH " > > unq_rows = Entry.find_by_sql( > select distinct #{flds} from entries " > ).each {|e| > ¨Â Åîôòù®æéî䨺áì쬺ãïîäéôéïî½¾ Ûóìãô¬å®áôôòéâõôåóÝ© > ¨Âõôï®ìåîçôè > > } > > When I do "pp e.attributes", it displays the following hash: > > {"OCRACR"=>"O", "MSG"=>"", "KEYCODE"=>"212260", "VERSION"=>"01", > "DEPTH"=>"001"} > > Shouldn't the find :conditions be ok? ¨Âèå óìãô óôòéîç áððåáò> formatted ok. ¨Âèå ®áôôòéâõôåèáóè áððåáòôï íáôãôèºãïîäéôéïî> string. ¨Â§í áô ìïóó æï÷èáô áí äïéîéîãïòòåãôìù® > > Thanks again, > dvn And I'll follow this up with the following that does function: unq_rows = Entry.find_by_sql( "select distinct #{flds} from entries " ).each {|e| slct = "" e.attributes.each {|key,value| slct << "#{key} = '#{value}' and " if key != 'id' } o = Entry.find(:all,:conditions => slct[0,slct.length-4] ) puts "#{e.KEYCODE} #{o.length}" } I'm sure the error is related to :KEYCODE versus 'KEYCODE' in the hash key. Let me ask a simpler question: What is the easiest method for getting the COUNT of rows for each distinct set of column values. In the above case, I want to get the count of rows for each unique combination of column values. Is there a simpler sql solution? Thanks again for any responses, dvn