完整性约束违规:1052列和where子句不明确

时间:2017-11-11 04:05:53

标签: mysql sql-server laravel eloquent

我有Tbl_payroll_leave_employeev2tbl_payroll_leave_schedulev2两个表,我想join他们但是我得到这样的错误

  

SQLSTATE [23000]:完整性约束违规:1052列&#39; payroll_leave_employee_id&#39; where子句不明确(SQL:从payroll_employee_id tbl_payroll_leave_employee_v2 tbl_payroll_leave_schedulev2 tbl_payroll_leave_employee_v2 payroll_leave_employee_id tbl_payroll_leave_schedulev2 payroll_leave_employee_id payroll_leave_employee_id $employee_id = Tbl_payroll_leave_employeev2::select('payroll_employee_id') ->join('tbl_payroll_leave_schedulev2','tbl_payroll_leave_employee_v2.payroll_leave_employee_id','=','tbl_payroll_leave_schedulev2.payroll_leave_employee_id') ->where('payroll_leave_employee_id',$emp) ->get(); window.setTimeout() <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> </head> <body> <h1>Green Planet</h1> <p id="greenplanet">All is well</p> <h1>Red Planet</h1> <p >Nothing to report</p> <h1 >Blue Planet</h1> <p >All systems A-OK</p> <script> function init() { window.setTimeout(function() { var planet = document.getElementById("greenplanet"); planet.innerText = "Red Alert: hit by phaser fire!"; planet.setAttribute("class","redtext"); alert("it initialized"); }, 1000); } window.onload=init; </script> </body> </html> } N = 5)◀

我的表结构 enter image description here

N

1 个答案:

答案 0 :(得分:2)

在where条件中,您必须定义表格payroll_leave_employee_id或表格tbl_payroll_leave_employee_v2

的字段tbl_payroll_leave_schedulev2
$employee_id = Tbl_payroll_leave_employeev2::select('payroll_employee_id')
   ->join('tbl_payroll_leave_schedulev2','tbl_payroll_leave_employee_v2.payroll_leave_employee_id','=','tbl_payroll_leave_schedulev2.payroll_leave_employee_id')
   ->where('tbl_payroll_leave_schedulev2.payroll_leave_employee_id',$emp)
   ->get();