Selecting records of a column which has two values separated by comma

10 views
Skip to first unread message

honey ruby

unread,
Oct 28, 2015, 3:00:42 AM10/28/15
to Ruby on Rails: Talk
Hi all,

In a table there is column called village which is text datatype. Now my question is few records will have 1,2 under village column some records will have only 2 or 1. when I do query I should be able to select those records which has 1,2 . If I want to select all the records of village(2). How can I do this in rails query.

Tried with Like and IN (?) in query but did not work

City.find(:all, :conditions => ["village LIKE ?",2])
City.find(:all, :conditions => ["village IN (?)",2])
 as it is text datatype and if I pass 1,2 I am able to get the records but while passing single value like 1 or 2

Kindly suggest how to get it


Thanks in advance

Colin Law

unread,
Oct 28, 2015, 4:21:54 AM10/28/15
to Ruby on Rails: Talk
Don't store the data like that, it will cause you endless problems and
you will look back in the future and ask why you did it that way.
Possibly it should be in separate fields, or even in a separate table.
It depends what the data represents. If you provide the context then
it may be possible to suggest the best alternative.

Colin

honey ruby

unread,
Oct 28, 2015, 6:31:40 AM10/28/15
to Ruby on Rails: Talk
thanks. I fixed it. Sure I will consider your suggestion.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvzeWMA7nVB1WW9ZAE%2BW15JTuFpEjdko125DpL0h4BVGA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages