I am in a need of running a complex SQL query and because I didn\'t know how to construct the query using ActiveRecod, I had to use a raw SQL query by using find_by_sql
find_by_sql