How to make this SQL Query?

0 views
Skip to first unread message

Fernando Santos

unread,
Jan 5, 2011, 3:35:11 PM1/5/11
to NoSQL-br
Hello guys,

I have a problem with how to do a sql query.

I have 3 tables: courses, times and courses_times

So for example, if i have the following data:

Courses courses_times Times
id | name course_id | time_id id | day

1 | Math 1 | 1 1
| Monday
2 | Chimestry 1 | 2 2 |
Wednesday
3 | History 1 | 3 3
| Friday
4 | Geografy 2 | 1
2 | 2
3 | 1


So, now, i want to make a query that returns to me only the courses
that are ministred on Monday,
but just ONLY Monday. For example, if a course is ministred Monday and
Wednesday i dont want.
In this example, i would like that my query returns just History,
because is the only course
that is just on Monday.


SELECT 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.day = 'Monday'

When i use a query like above, for example, it returns to me all the
courses that have association with Monday,
it returns Math, Chimestry and History, and i would like to receive
just History




Does anyone have a solution for this?

Thanks a lot

Fernando
Reply all
Reply to author
Forward
0 new messages