Jump to content

How to select and display records from multiple tables


jfaust97

Recommended Posts

I am trying to select and display data from multiple tables.

 

Table #1 is called 'classes':

id

category

title

date

id_number

max_attend

num_enrolled

 

 

Table #2 is called 'students':

classes_id

fname

lname

email

phone

 

 

I think I want to select the 'classes' that have 'students' where id.classes = classes_id.students

But I am not sure how to write that select statement.

 

Furthermore I want to list each class and the students that are enrolled in that class.

So I ma not sure how to write that while loop either.

 

Can anyone offer assistance?

Greatly appreciated!

 

 

 

 

I`ve posted the same replay in two other similar posts so i`ll refrain from saying it once more! :-X

then again . .

 

What you need is a function (if you can call it that) called Join!

 

Try http://dev.mysql.com/doc/refman/5.0/en/join.html or

http://www.tizag.com/mysqlTutorial/mysqljoins.php.

 

I myself prefer the latter. ;D

I think I want to select the 'classes' that have 'students' where id.classes = classes_id.students

But I am not sure how to write that select statement.

Try:

 

select s.*, c.* from classes as c inner join students on c on c.id. = s.classes_id

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.