Search code examples
sqlruby-on-railsruby-on-rails-2

How do this sql query in rails 2.3?


I need this sql query in a function in my controller in ruby on rails 2.3.

SELECT name, created_at AS "date" FROM table1 WHERE created_at = '2015-07-15' ORDER by created_at;

This is because I have two more queries before this one, and they have a field named 'date', and I need to concatenate every one and sort them by the field named 'date', and just this last one table don't have a field named 'date'.


Solution

  • Ok, I found this solution that helps me, for another person maybe need it..

    table1.find_by_sql["SELECT name, created_at AS 'date' FROM table1 WHERE created_at = '2015-07-15' ORDER by created_at"]

    Then I can sort all my query results (including the previous tables) by the field 'date'..