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
怎么做?
答案 0 :(得分:0)
使用JOIN
SELECT *
FROM ride r inner join route_through rt on r.id = rt.id
WHERE from=$from and to=$to