我在使用 sql 查询时遇到问题
这是我的查询:
SELECT `rooms`.*
FROM `rooms`
WHERE (`rooms`.`room_id` NOT IN (
SELECT *
FROM `reservations` `res`
WHERE ('2012-05-03' NOT BETWEEN res.expected_checkin_date
AND res.expected_checkout_date)
AND ('2012-05-08' NOT BETWEEN res.expected_checkin_date
AND res.expected_checkout_date)))
问题是当第二个select
返回null时,它显示以下错误:
#1241 - Operand should contain 1 column(s)
有谁能够帮助我?
EDIT
当我运行此查询时,它会显示所有行,甚至包括第二行内的行,select
我不知道为什么?
SELECT `rooms`.*, `type`.*, `status`.* FROM `rooms` INNER JOIN `room_types` AS `type` ON `type`.`room_type_id` = `rooms`.`room_type_id` AND `type`.`num_beds` >= 1 AND type.room_type_id=2 INNER JOIN `room_statuses` AS `status` ON `status`.`room_status_id` = `rooms`.`room_status_id` WHERE (`rooms`.`room_id` NOT IN (SELECT `res`.`room_id` FROM `reservations` `res` WHERE (res.expected_checkin_date >= '2012-05-01' AND res.expected_checkin_date < '2012-05-31') AND (res.expected_checkout_date >= '2012-05-31' AND res.expected_checkout_date < '2012-05-31')))