Sql query

hi

i have such a model and im not sure how to get the data out:

Task:

  • project_id
  • name
  • timestamp
  • value (progress)

now, an insert always insert multiple rows at the same time, but name
has
different values and so does ‘value’

i need a query which gets all tasks for one or more projects, but only
the
last group of names + values in terms of the timestamp (the most recent
group)

im tryin in mysql, aka:
select * from tasks where project == 123 and timestamp = (select max
timestamp from tasks where project = 123)

not sure how to get all projects…and in rails

On Mon, Dec 22, 2014 at 10:41 AM, tom [email protected] wrote:

i need a query which gets all tasks for one or more projects, but only the
last group of names + values in terms of the timestamp (the most recent
group)

I’m not sure I exactly understand that, but the easiest way to clarify
(or figure it out yourself) is to write a test.

Start with a fixture or some factory code to generate representative
data. Then write the test that shows exactly your expectation of the
data to be returned. Then write the method that does that :slight_smile:

If you’re stuck on the last part, you can at least post your example
data and failing test to get better advice.

FWIW,

Hassan S. ------------------------ [email protected]

twitter: @hassan