Reputation: 834
I have three different tables I am trying to pull info from. Related in different ways. I am trying to find a Join statement that will allow me to pull the information a little better than using the two queries I am now.
Here is what I have
SELECT * FROM reports LEFT JOIN students USING (sID)
This allows me to properly merge the two tables. However - There is a row in the reports table named pID. I have another table named test, that also has a matching pID row, along with other data. I am trying to access the data from that table as well. Is it possible to join three tables in that way? Not only getting data from the sID, but the pID as well
Upvotes: 2
Views: 1528
Reputation: 8873
Hi robert yes it is posible. You can do a query like as shown below given your three tables, reports, students, and test.
SELECT *
FROM `reports`
LEFT JOIN `students` ON `students.sid=reports.sid`
LEFT JOIN `test` ON `reports.pid=tests.pid`
Upvotes: 2
Reputation: 14941
You can do the following
SELECT *
FROM reports
LEFT JOIN students USING (sID)
LEFT JOIN table3 USING (pID)
Where table3
is the name of your table.
Upvotes: 4