SQL Inner join more than two tables

后端 未结 10 1147
感情败类
感情败类 2020-11-29 23:21

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` 
         


        
10条回答
  •  攒了一身酷
    2020-11-30 00:12

    Try this Here the syntax is

    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

提交回复
热议问题