The second one would be better, because the aggregation is performed before, you will have one step less on the temporary table than with the first query.
However take a look at the execution plan, with the EXPLAIN .
문제
I have two ways to select MAX values from two tables but don't know which one is better or faster.
i checked from mysql workbench
but in case both query i'm getting 0.00 Sec
execution time
First query
SELECT MAX(s) from (
SELECT sheetid s FROM csheets
UNION all
SELECT sheetid s FROM queueitems
) as t
Explain
Second Query
SELECT MAX(s) from (
SELECT MAX(sheetid) s FROM csheets
UNION all
SELECT MAX(sheetid) s FROM queueitems
) as t
Explain So question is which one better in terms of speed?
올바른 솔루션이 없습니다
다른 팁
The second one would be better, because the aggregation is performed before, you will have one step less on the temporary table than with the first query.
However take a look at the execution plan, with the EXPLAIN .