我有三個表SQL JOIN操作
CREATE TABLE IF NOT EXISTS `tbl_hotelinfo` (
`hotel_id` int(11) NOT NULL AUTO_INCREMENT,
`hotel_name` varchar(20) NOT NULL,
`hotel_normal_room` int(3) NOT NULL,
`hotel_delux_room` int(3) NOT NULL,
`hotel_nonac_room` int(3) NOT NULL,
`hotel_ac_room` int(3) NOT NULL,
`hotel_owner_email` varchar(20) NOT NULL,
`hotel_owner_index` int(11) NOT NULL,
`hotel_state` varchar(11) NOT NULL,
`hotel_district` varchar(11) NOT NULL,
`hotel_phno` int(13) NOT NULL,
`hotel_location` varchar(20) NOT NULL,
PRIMARY KEY (`hotel_id`)
)
CREATE TABLE IF NOT EXISTS `tbl_hotelbooking` (
`hotel_id` int(11) NOT NULL,
`normal_room_booked` int(3) NOT NULL DEFAULT '0',
`delux_room_booked` int(3) NOT NULL DEFAULT '0',
`nonac_room_booked` int(3) NOT NULL DEFAULT '0',
`ac_room_booked` int(3) NOT NULL DEFAULT '0'
)
CREATE TABLE IF NOT EXISTS `tbl_room_types` (
`hotel_id` int(11) NOT NULL,
`hotel_normal_room` enum('yes','no') NOT NULL DEFAULT 'no',
`hotel_delux_room` enum('yes','no') NOT NULL DEFAULT 'no',
`hotel_nonac_room` enum('yes','no') NOT NULL DEFAULT 'no',
`hotel_ac_room` enum('yes','no') NOT NULL DEFAULT 'no',
`normal_fair` int(11) NOT NULL,
`delux_fair` int(11) NOT NULL,
`non_ac_fair` int(11) NOT NULL,
`ac_fair` int(11) NOT NULL
)
現在我需要參加這三個表中查找HOTEL_NAME,hotel_location對於那些酒店,其房間可供 假設我們有HOTEL_ID可用的。首先我要找到每個room_type可現在特別HOTEL_ID hotel_room_types(其中枚舉類型是假設只針對正常室溫枚舉類型是肯定的),檢查自己是否tbl_hotelinfo.hotel_normal_room> tbl_hotelbooking.normal_room_booked 試圖
$q="SELECT total.hotel_name ,total.hotel_phno
FROM tbl_hotelbooking AS book ,
tbl_hotelinfo AS total,
tbl_room_types AS rtype
WHERE
SELECT * from tbl_room_types
rtype.hotel_id='$hotel_id'
";
什麼是這裏的實際問題? – codeling 2011-12-14 07:13:59