How can I optimize the following code so I do not use 3 SELECTs and do not match the query to just 3 status
(
SELECT *
FROM historico
WHERE
his_status = 'FRACASSO'
ORDER BY his_data DESC
LIMIT 50
)
UNION ALL
(
SELECT *
FROM historico
WHERE
his_status = 'REAVALIAR'
ORDER BY his_data DESC
LIMIT 50
)
UNION ALL
(
SELECT *
FROM historico
WHERE
his_status = 'SUCESSO'
ORDER BY his_data DESC
LIMIT 50
)
Currently I have 2562 records in the historical table and I'm using all of them to train an RNA. It costs 3 to 4 minutes. This query will enable the user to enter how many samples of each status you want to use. Amount 50 is an example. The optimization of the query is also to reduce the cost of time.