SQL Inner join more than two tables

后端 未结 10 1164
感情败类
感情败类 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: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'
    

提交回复
热议问题