1

what is the Ruby code equivalent to following mysql query? I'm trying to search for an exact match of a string eg.'MAIN' and 'Main' should be treat different.

SELECT UserID FROM sys_users WHERE BINARY UserID='MAIN'
Ashwini
  • 2,449
  • 2
  • 29
  • 42

3 Answers3

2

It's just like:

SysUser.select('UserID').where('BINARY UserID=?', 'MAIN')
xdazz
  • 158,678
  • 38
  • 247
  • 274
0

A very quick look at ActiveRecord guide gives the answer:

2.1 Pure String Conditions If you’d like to add conditions to your find, you could just specify them in there, just like Client.where("orders_count = '2'"). This will find all clients where the orders_count field’s value is 2.

You could have easily found this through google...

Also, case sensitivity is not Rails responsibility but depends on your database settings. Hint: You should switch default collation to UTF-8.

Community
  • 1
  • 1
Arnaud Rinquin
  • 4,296
  • 1
  • 30
  • 51
0

Ruby code equivalent to mysql query:

SysUser.where("UserID='MAIN'").select('UserID')
Deepika
  • 826
  • 6
  • 14