Jump to content

Help With Query to Multiple Tables


bobbyv102

Recommended Posts

Hello,

As the post states I am fairly new to PHP. I am working on a database in MS SQL and what I am trying to do is use a PHP web page to pull data from it. The original script works to pull from one table, but now I need it to pull from 3 seperate tables.

The database stores:

1. list of instructors = tblInstructors
-Instructor id = eeid
- instructor first name = fname
- instructor last name = lname
2. list of Classes = tblSchedule
-Course id = id
- instructor name = fname
- start date = Date
-end date = EndDate
3. the survey responses = tblPostClassSurvey
- 12 different survey question fields
- survey id = id
- course id = CourseID

I need all the results from post class survey, but only of the name of the instructor which is stored in the php variable $instructor, and the date grouped by the date. Unfortunately I do not have the code I have used so far here at home, but a point in the right direction will help. I found several resources that used the join option and pulling my fields with dot notation (ie: tblSchedule.id) but that does not return anything. Any help woul dbe great help.

Thanks
Robert
Link to comment
https://forums.phpfreaks.com/topic/12355-help-with-query-to-multiple-tables/
Share on other sites

It's more then a database question then a php problem I think. You could use a query like:

[code]
SELECT tb1.id,tb2.id,tb3.id FROM tb1,tb2,tb3 WHERE tb1.id=tb2.id
[/code]
where in this code tb1 stands for table names. You could use such a query. Or It seems that you have some where clauses which use some values pulled from db. You could such a query:
[code]
SELECT id FROM tb1 WHERE id IN ( SELECT id FROM tb2 WHERE id IN ( SELECT id FROM tb3 WHERE fname='myname' ) )
[/code]
id will take values which the in statement returns and if our in statement return 2 and 3 our code will be like:
[code]
SELECT id FROM tb1 WHERE id = 2 OR id = 3
[/code]

Is this helps?

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.