|
|
|
| Собственно сабж. Особенно интересно можно ли объединить всё это в один запрос? Я пробовал, но у меня дублировались строки, по этому решил юзать UNION. Так же интересует вопрос безопасности.
SELECT scf.city, sct.city,
CASE WHEN (scv.city = '.$_POST["city_from"].' AND sr.city_to = '.$_POST["city_to"].') THEN scv.time_finish
ELSE sh_time.start
END, sh_time.weekday, sr.id, sh_time.id
FROM (schedule_via scv, schedule_time sh_time)
JOIN schedule_route sr ON sr.id = scv.route_id
JOIN schedule_cities scf ON scf.id = sr.city_from
JOIN schedule_cities sct ON sct.id = sr.city_to
WHERE ((scv.city = '.$_POST["city_from"].' AND sr.city_to = '.$_POST["city_to"].')
OR (sr.city_from = '.$_POST["city_from"].' AND scv.city = '.$_POST["city_to"].'))
AND sh_time.route_id = sr.id AND sr.id = scv.route_id
UNION
SELECT scf.city, sct.city, scv.time_finish, sh_time.weekday, sr.id, sh_time.id
FROM (schedule_via scv, schedule_time sh_time)
JOIN schedule_route sr ON sr.id = scv.route_id
JOIN schedule_via scv_1 ON scv_1.route_id = sr.id
JOIN schedule_cities scf ON scf.id = sr.city_from
JOIN schedule_cities sct ON sct.id = sr.city_to
WHERE scv.city = '.$_POST["city_from"].' AND scv_1.city = '.$_POST["city_to"].'
AND scv.city_num < scv_1.city_num AND sh_time.route_id = sr.id AND sr.id = scv.route_id
ORDER BY 3 ASC
|
Заранее спасибо за советы и замечания. | |
|
|