Есть ли возможность как-то оптимизировать следующий запрос? Спасибо!
SELECT t_ps.*, cl.*, c.*, ml.description, m.name as m_name
FROM `tt_payment_settings` t_ps
JOIN `tt_card` c ON t_ps.id_card = c.id_card
JOIN `tt_card_lang` cl ON cl.id_card = c.id_card
JOIN `tt_module` m USING (id_module)
JOIN `tt_module_lang` ml ON ml.id_module = t_ps.id_module
WHERE IF(
(
SELECT COUNT(t_ps.id_payment_settings)
FROM `tt_payment_settings` t_ps
JOIN `tt_card` c ON t_ps.id_card = c.id_card
JOIN `tt_card_lang` cl ON cl.id_card = c.id_card
JOIN `tt_module` m USING (id_module)
JOIN `tt_module_lang` ml ON ml.id_module = t_ps.id_module
WHERE t_ps.id_shop = 651
AND t_ps.id_season = 7
AND cl.id_lang = 1
AND ml.id_lang = 1
)>0
, t_ps.id_shop = 651
AND t_ps.id_season = 7
AND cl.id_lang = 1
AND ml.id_lang = 1
, t_ps.id_shop = 651
AND t_ps.id_season IS NULL
AND cl.id_lang = 1
AND ml.id_lang = 1
)
--- UPD
Переделал так:
SELECT tt.*, cl.*, c.*, ml.description, m.name as m_name
FROM `tt_payment_settings` ps
JOIN `tt_card` c ON tt.id_card = c.id_card
JOIN `tt_card_lang` cl ON cl.id_card = c.id_card
JOIN `tt_module` m USING (id_module)
JOIN `tt_module_lang` ml ON ml.id_module = tt.id_module
WHERE tt.id_shop = 651
AND cl.id_lang = 1
AND ml.id_lang = 1
AND tt.goo_active = 1
AND
IF(
EXISTS(SELECT *
FROM `tt_payment_settings` ps
WHERE tt.id_shop = 651
AND tt.id_season = 7)
,tt.id_season = 7
,tt.id_season IS NULL
)
Если можно еще как-то лучше буду рад увидеть