mysql - Eliminate duplicate records in rail where condition -


i trying fetch record has unique value .below output getting after using

vouchernumber.where(:goodie=> 2917) [#<vouchernumber id: 559, vendor_id: 5, voucher_number: "1", trip_id: nil, expiry_date: "2016-03-23 18:30:00", goodie_id: 2917, status: "un", amount: #<bigdecimal:8f9b7f0,'0.122e3',9(36)>, created_at: "2016-03-04 11:37:22", updated_at: "2016-03-04 11:37:22">, #<vouchernumber id: 565, vendor_id: 5, voucher_number: "4", trip_id: nil, expiry_date: "2016-03-23 18:30:00", goodie_id: 2917, status: "un", amount: #<bigdecimal:8faf750,'0.122e3',9(36)>, created_at: "2016-03-04 11:37:22", updated_at: "2016-03-04 11:37:22">, #<vouchernumber id: 567, vendor_id: 11, voucher_number: "sss", trip_id: nil, expiry_date: "2016-03-22 18:30:00", goodie_id: 2917, status: "un", amount: #<bigdecimal:8fad7c0,'0.112e3',9(36)>, created_at: "2016-03-04 11:37:22", updated_at: "2016-03-04 11:37:22">, #<vouchernumber id: 569, vendor_id: 11, voucher_number: "22", trip_id: nil, expiry_date: "2016-03-22 18:30:00", goodie_id: 2917, status: "un", amount: #<bigdecimal:902d510,'0.112e3',9(36)>, created_at: "2016-03-04 11:37:22", updated_at: "2016-03-04 11:37:22">]..    expected output below output [#<vouchernumber id: 559, vendor_id: 5, voucher_number: "1", trip_id: nil, expiry_date: "2016-03-23 18:30:00", goodie_id: 2917, status: "un", amount: #<bigdecimal:8f9b7f0,'0.122e3',9(36)>, created_at: "2016-03-04 11:37:22", updated_at: "2016-03-04 11:37:22"> #<vouchernumber id: 567, vendor_id: 11, voucher_number: "sss", trip_id: nil, expiry_date: "2016-03-22 18:30:00", goodie_id: 2917, status: "un", amount: #<bigdecimal:8fad7c0,'0.112e3',9(36)>, created_at: "2016-03-04 11:37:22", updated_at: "2016-03-04 11:37:22">] 

can 1 point me in right direction?

you can try way returns vendor_id

vouchernumber.where(:goodie=> 2917).uniq.pluck(:vendor_id) 

you can find columns using goodie goodie , vendor_id uniq

vouchernumber.group("goodie,vendor_id") 

for selected goodie as:

vouchernumber.where(:goodie=> 2917).group(:vendor_id) 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -