I did join on three tables.
arel = OfferOrder.includes(:a, :b, :c) arel = arel.select('(CASE WHEN ISNULL(c.field2) THEN c.field1 ELSE c.field2 END) AS fraud') but when I run my code it gives error that (Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS fraud) -- 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-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/HNyCdaXFyX4J. For more options, visit https://groups.google.com/groups/opt_out.