I have Mysql query, something like this:
SELECT
Main.Code,
Nt,
Ss,
Nac,
Price,
Ei,
Quant,
Dateadded,
Sh,
Crit,
CAST(Ss * Quant AS DECIMAL (10 , 2 )) AS Qss,
CAST(Price * Quant AS DECIMAL (10 , 2 )) AS Qprice,
`Extra0`.`Value`
FROM
Main
LEFT OUTER JOIN
`Extra_fields` AS `Extra0` ON `Extra0`.`Code` = `Main`.`Code`
AND `Extra0`.`Nf` = 2
ORDER BY `Code`
The query is very slow (about 10 sec.). The query without this part:
LEFT OUTER JOIN Extra_fields AS Extra0 ON Extra0.Code = Main.Code AND Extra0.Nf=2
is fast.
Is there some way to optimize first query?
SHOW CREATE TABLEfor both tables.