0
CREATE TABLE IF NOT EXISTS `ride` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`from` text CHARACTER SET utf8 COLLATE utf8_polish_ci NOT NULL,
`to` text CHARACTER SET utf8 COLLATE utf8_polish_ci NOT NULL,
PRIMARY KEY (`id`)
)
CREATE TABLE IF NOT EXISTS `route_through` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_ride` int(11) NOT NULL,
`city` text COLLATE utf8_polish_ci NOT NULL,
PRIMARY KEY (`id`)
)
搜索路线,我需要寻找ride
:经过许多城市
SELECT * FROM ride WHERE from=$from and to=$to
如何搜索,如果我在route_through
有城市?
例如:
ride
表:
id
= 1
from
=巴黎
to
=伦敦
route_through
表:
id
= 1
id_ride
= 1
city
= '皇马'
搜索形式:
现在我在形式上这个城市设置:from
- 马德里to
伦敦。这应该返回ride
与id
= 1
如何做到这一点?
请记住,一个'ride'可以有多个'route_through'记录,在这种情况下该查询将返回包含** **一样乘坐多行,但每一个**不同** route_through – thaJeztah 2013-04-03 18:54:46
@thaJeztah然后他可以添加额外的逻辑。 – 2013-04-03 18:55:44
同意,只是把我的意见通知OP的后果,因为他显然不是很有经验。如果只需要'route_through'的*名称*,一个简单的'GROUP_CONCAT()'就足够了 – thaJeztah 2013-04-03 18:59:12