我有其中有两个以人为我想为行返回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