lightnb
01-03-2008, 03:00 PM
Assuming the following table structure:
Table "Schools"
------------------
ID
SchoolName
Table "Users"
------------------
ID
UserName
Table "UserSchools"
------------------
SchoolID
UserID
How can I get a result row that has the user's name, and all of their school's names, with a single query, using MySQL (version 5.0.38)?
Say for example that I wanted to print a list of users, followed by their school(s).
The way I'm doing it now would require me to first run a query to get all the users and their ids, and then run another query (in a loop) for every user to get their schools. That means if there's 100 users shown, I have to run 101 queries!
Can someone tell me a more effective way to do this?
Table "Schools"
------------------
ID
SchoolName
Table "Users"
------------------
ID
UserName
Table "UserSchools"
------------------
SchoolID
UserID
How can I get a result row that has the user's name, and all of their school's names, with a single query, using MySQL (version 5.0.38)?
Say for example that I wanted to print a list of users, followed by their school(s).
The way I'm doing it now would require me to first run a query to get all the users and their ids, and then run another query (in a loop) for every user to get their schools. That means if there's 100 users shown, I have to run 101 queries!
Can someone tell me a more effective way to do this?