我需要排除类似于 MINUS 的第二个查询(来自第二个表的数据)。但由于 MySQL 不支持 MINUS,我决定使用 LEFT JOIN。但是它给了我一个数据库错误。
模型
function searchRooms($room_type, $start_date, $end_date) {
// Line 6 is the below one:
$query = $this->db->query(
"SELECT room_number
FROM rooms
WHERE room_type = '$room_type'
ORDER BY room_number ASC
LEFT JOIN
SELECT room_number
FROM new_reservation
WHERE start_date >= '$start_date'
AND end_date <= '$end_date'
ORDER BY room_number ASC
");
return $query->result();
}
控制器
function search() {
$room_type = $this->input->post('room_type');
$start_date = $this->input->post('start_date');
$end_date = $this->input->post('end_date');
$this->reservations_model->searchRooms($room_type, $start_date, $end_date);
$this->index();
}