Robert Dickey Robert Dickey - 7 months ago 11
PHP Question

MySQL Join Query with Multiple Joins

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

Answer

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.

Comments