I have the following question to answer:
For each tag, retrieve the 10 to-dos with quickest completion time (i.e. the time between the creation and the completion of the to-do)
From ToDoItem, Tag, ItemTag
time between CreationDate and
CompletionDate is ASC AND
Tag.Id = ItemTag.ToDoId AND
ItemTag.TagId = ToDoItem.Id
2 issues with your query:
You need to use
datediff() function to get the time between.
Ordering the results ahould be done with
order by statement, not in the where part.
Select * From ToDoItem, Tag, ItemTag Where Tag.Id = ItemTag.ToDoId AND ItemTag.TagId = ToDoItem.Id Order by datediff(completiontime, creationtime) asc Limit 10