Смена условия в переменной при запросе
В общем, мне нужно сделать так.
Если при JOIN ничего нет, то подсунуть ему другое условие JOIN, но с сохранением в ту же переменную. Как это можно сделать?
SELECT
profile_orders.id id,
user_id,
user_name,
DATE_FORMAT(`date`, '%d/%m/%Y %H:%i') `date`,
status,
`from`,
`where`,
model_plane,
flight_hours,
price,
passengers,
a1.name_rus name_rus_from,
a1.name_eng name_eng_from,
a2.name_rus name_rus_where,
a2.name_eng name_eng_where,
a1.city_rus city_rus_from,
a1.city_eng city_eng_from,
a2.city_rus city_rus_where,
a2.city_eng city_eng_where,
a1.country_rus country_rus_from,
a1.country_eng country_eng_from,
a2.country_rus country_rus_where,
a2.country_eng country_eng_where,
bort.model_vts model_vts,
bort.model_id model_id,
bort.airport_icao airport_icao
FROM profile_orders
JOIN calc_airport a1 ON a1.icao_code = profile_orders.`from`
JOIN calc_airport a2 ON a2.icao_code = profile_orders.`where`
(JOIN airplanes_table bort ON bort.bort_number = profile_orders.model_plane)
OR (JOIN airplanes_table2 bort ON bort3.bort_number = profile_orders1.model_plane)
WHERE user_id = 1
Подумал, как нибудь так, но эта конструкция не валидна.
(JOIN airplanes_table bort ON bort.bort_number = profile_orders.model_plane)
OR (JOIN airplanes_table2 bort ON bort3.bort_number = profile_orders1.model_plane)
Источник: Stack Overflow на русском