SQL Inner join more than two tables

后端 未结 10 1082
感情败类
感情败类 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-29 23:57
    SELECT * 
    FROM table1 
    INNER JOIN table2
          ON table1.primaryKey=table2.table1Id
    INNER JOIN table3
          ON table1.primaryKey=table3.table1Id
    
    0 讨论(0)
  • 2020-11-30 00:02

    The right syntax is like:

    SELECT * FROM table1 INNER JOIN table2 ON table1.primaryKey = table2.ForeignKey
    INNER JOIN table3 ON table3.primaryKey = table2.ForeignKey
    

    Orthe last line joining table3 on table1 like:

    ON table3.ForeignKey= table1.PrimaryKey
    
    0 讨论(0)
  • 2020-11-30 00:02

    try this method given below, modify to suit your need.

    SELECT
      employment_status.staff_type,
      COUNT(monthly_pay_register.age),
      monthly_pay_register.BASIC_SALARY,
      monthly_pay_register.TOTAL_MONTHLY_ALLOWANCES,
      monthly_pay_register.MONTHLY_GROSS,
      monthly_pay_register.TOTAL_MONTHLY_DEDUCTIONS,
      monthly_pay_register.MONTHLY_PAY
    FROM 
      (monthly_pay_register INNER JOIN deduction_logs 
    ON
      monthly_pay_register.employee_info_employee_no = deduction_logs.employee_no)
    INNER JOIN
      employment_status ON deduction_logs.employee_no = employment_status.employee_no
    WHERE
      monthly_pay_register.`YEAR`=2017
    and 
      monthly_pay_register.`MONTH`='may'
    
    0 讨论(0)
  • 2020-11-30 00:04
    select * from Employee inner join [Order] 
    On Employee.Employee_id=[Order].Employee_id
    inner join Book 
    On Book.Book_id=[Order].Book_id
    inner join Book_Author
    On Book_Author.Book_id=Book.Book_id
    inner join Author
    On Book_Author.Author_id=Author.Author_id;
    
    0 讨论(0)
  • 2020-11-30 00:07
    select WucsName as WUCS_Name,Year,Tot_Households,Tot_Households,Tot_Male_Farmers  from tbl_Gender
    INNER JOIN tblWUCS
    ON tbl_Gender.WUCS_id =tblWUCS .WucsId 
    INNER JOIN tblYear
    ON tbl_Gender.YearID=tblYear.yearID
    

    There are 3 Tables 1. tbl_Gender 2. tblWUCS 3. tblYear

    0 讨论(0)
  • 2020-11-30 00:08
    SELECT eb.n_EmpId,
       em.s_EmpName,
       deg.s_DesignationName,
       dm.s_DeptName
    FROM tbl_EmployeeMaster em
     INNER JOIN tbl_DesignationMaster deg ON em.n_DesignationId=deg.n_DesignationId
     INNER JOIN tbl_DepartmentMaster dm ON dm.n_DeptId = em.n_DepartmentId
     INNER JOIN tbl_EmployeeBranch eb ON eb.n_BranchId = em.n_BranchId;
    
    0 讨论(0)
提交回复
热议问题