I can currently query the join of two tables on the equality of a foreign/primary key in the following way.
$result = mysql_query(\"SELECT * FROM `table1`
A possible solution:
SELECT Company.Company_Id,Company.Company_Name,
Invoice_Details.Invoice_No, Product_Details.Price
FROM Company inner join Invoice_Details
ON Company.Company_Id=Invoice_Details.Company_Id
INNER JOIN Product_Details
ON Invoice_Details.Invoice_No= Product_Details.Invoice_No
WHERE Price='60000';
-- tets changes
SELECT table1 .columnName, table3 .columnName
FROM table1
inner join table2
ON table1.primarykey = table2.foreignkey
inner join table3
ON table2.primarykey = table3.foreignkey
for example:
Select SalesHeader.invoiceDate,ActualSales,DeptName,tblInvDepartment.DeptCode ,LocationCode from SalesDetail Inner Join SalesHeader on SalesDetail.InvoiceNo = SalesHeader.InvoiceNo inner join tblInvDepartment on tblInvDepartment.DeptCode = SalesDetail.DeptCode
Here is a general SQL query syntax to join three or more table. This SQL query should work in all major relation database e.g. MySQL, Oracle, Microsoft SQLServer, Sybase and PostgreSQL :
SELECT t1.col, t3.col FROM table1 join table2 ON table1.primarykey = table2.foreignkey
join table3 ON table2.primarykey = table3.foreignkey
We first join table 1 and table 2 which produce a temporary table with combined data from table1 and table2, which is then joined to table3. This formula can be extended for more than 3 tables to N tables, You just need to make sure that SQL query should have N-1 join statement in order to join N tables. like for joining two tables we require 1 join statement and for joining 3 tables we need 2 join statement.
Please find inner join for more than 2 table here
Here are 4 table name like
So the SQL code would be:
select o.orderid, c.customername, l.lname, s.studadd, s.studmarks
from orders o
inner join customers c on o.customrid = c.customerid
inner join lecturer l on o.customrid = l.id
inner join student s on o.customrid=s.studmarks;