Wednesday, 2 October 2013

Selecting results from 2 tables based on the variables in 3th table

Selecting results from 2 tables based on the variables in 3th table

I have 2 tabes in my database:
users - userID(primary key), username, password
courses - id(primary key), name, text
subscriptions - id(primary key), curso_id, user_id
right in the subscription table I am writing the users UserID inside ->
user_id with the id of the course for which he is subscribed curso_id so
the results in the subscrption database are like
id user_id curso_id
1 12 1
2 5 1
3 12 2
4 6 7
My question is how to make a sql Query which first select the course by
$row['id'] which indicates the id variable from the courses database, and
after that based on the 3th table subscription to list all the users which
are subscribed to this course number. ?
and second question is how to list number of the subscribed users for a
course selected by
$row['id']

No comments:

Post a Comment