djangst,
hum.... but actually in my database it occurs... that are some coursers that have two times that reffers to the same day (because actually in my db, time has the hour too, not only the day)
but, using Fred`s example, i would have to make a select in the courses and use that another select that fred used as a condition for this first select?
like this?
SELECT DISTINCT courses. *
FROM courses
INNER JOIN courses_times ON courses_times.course_id = courses.id
INNER JOIN times ON courses_times.time_id = times.id
AND times.dia = 'Monday'
WHERE EXISTS (
SELECT count( * ) AS times_scheduled
FROM courses_times
INNER JOIN courses_times AS other_times ON other_times.course_id = courses_times.course_id
WHERE courses_times.time_id = times.id
GROUP BY courses_times.course_id
HAVING times_scheduled =1
Sorry for the question but i`m new to sql and all this stuff..
Thanks
Fernando
Check out Fred's earlier example. Using the count of courses with only
one courses_times row in conjunction with the having clause you can
filter out courses scheduled on more than one day.
The only potential problem I could foresee with this would be if a
course could be scheduled for multiple times on the same day. But
that's not reflected in the data model you posted so it shouldn't be
an issue.
On Jan 5, 1:50 pm, Fernando Leandro <fernandoleandro1...@gmail.com>
wrote:
> yes.. its exactly this... but how can i do that in another way?--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment