Inject SQL Statement in Rails

Hi,

I have a simple SQL statement which I would like to inject in my web
application. The SQL statement is:

Select course_id
from degrees
where programme_id = 1

I need to know the step by step on how to make this work. What changes
should be made to the model, view or controller? Urgent. Please reply
asap.
Thank you very much!

You can use find_by_sql to use MySQL directly:

@object.find_by_sql("SELECT course_id
FROM degrees
WHERE programme_id = 1
")

@object will be referenced with an array of entries from database.

yudi wrote:

You can use find_by_sql to use MySQL directly:

@object.find_by_sql("SELECT course_id
FROM degrees
WHERE programme_id = 1
")

@object will be referenced with an array of entries from database.

okay so i put this statement in the model right?

just curious, how does the view/controller know where to find this?

thanks everyone for all the help!

Check RailsEnvy for an ActiveRecord tutorial. You’ll find everything you
need over therehttp://www.railsenvy.com/2007/8/8/activerecord-tutorial