我想写的查询是
SELECT Equipment.Name, Equipment.EquipmentTag, LoanedOut.StudentNumber, LoanedOut.DueDate
FROM Equipment, LoanedOut
WHERE Equipment.EquipmentRecordID = LoanedOut.EquipmentRecordID AND LoanedOut.StudentNumber = 040828055
我无法弄清楚如何使用codeigniter的查询构建器来做到这一点,我到目前为止最好的是
$this->db->select('Equipment.Name, Equipment.EquipmentTag, LoanedOut.StudentNumber, LoanedOut.DueDate');
$this->db->from('Equipment e, LoanedOut l');
$this->db->join('l', 'e.EquipmentRecordID = l.EquipmentRecordID')->join('l', 'l.StudentNumber', $studentNumber);
答案 0 :(得分:0)
这会给你你想要的东西//
$sql = 'SELECT e.Name,e.EquipmentTag,l.StudentNumber,l.DueDate FROM Equipment e LEFT JOIN LoanedOut l ON e.EquipmentRecordID = l.EquipmentRecordID WHERE l.StudentNumber = "040828055"'
$query = $this->db->query($sql);