我有其中有兩個以人爲我想爲行返回PERSON_1,PERSON_2作爲新行,但與人的ID與百姓餐桌SQL連接兩個字段在一個表中
這是預訂表據我得到,但在預訂信息
SELECT people.* FROM (
(select booking.person_1 as id from booking)
union ALL
(select booking.person_2 as id from booking)
) as peopleids
join people on people.id = peopleids.id;
我的繼承人結構犯規拉
CREATE TABLE IF NOT EXISTS `booking` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`slot` enum('morning_drive','afternoon_loop','return_drive') NOT NULL,
`type` enum('911','vintage_911') NOT NULL,
`car` int(11) NOT NULL,
`person_1` int(11) DEFAULT NULL,
`person_2` int(11) DEFAULT NULL,
`dated` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
CREATE TABLE IF NOT EXISTS `people` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(50) NOT NULL,
`last_name` varchar(50) NOT NULL,
`organisation` varchar(100) NOT NULL,
`event_date` date NOT NULL,
`wave` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
如何,我能得到一個結果集喜歡 - person.first_name,person.last_name,人的任何想法.ORG anisation,booking.dated,person.car,person.slot。 IM具有兩個字段,並讓他們到它們與到一個列表
有興趣的人此更新,並在我的特定日期加入第3臺
繼承人我用PHP最終查詢瓦爾拉掙扎和插槽,並且還加入第三個表
SELECT peopleids.id,
peopleids.car,
cars.nr,
p.first_name,
p.last_name,
p.organisation,
p.event_date,
p.wave
FROM (SELECT booking.car, booking.person_1 as id FROM booking WHERE booking.dated = '".$date."' AND booking.`slot` = '".$slot."'
union ALL SELECT booking.car, booking.person_2 as id FROM booking WHERE booking.dated = '".$date."' AND booking.`slot` = '".$slot."'
) as peopleids
LEFT JOIN people p ON p.id = peopleids.id LEFT JOIN cars on cars.id = peopleids.car;
參加人people.id = peopleids.id? – StuartLC
這工作..但不允許我拉相關的預訂信息,最好的辦法是什麼? –
你需要選擇其餘的工會領域(選擇booking.person1,booking.someotherfield,booking.bookingdate) – StuartLC