Question

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 enter image description here

Second Query

SELECT MAX(s) from (
  SELECT MAX(sheetid)  s FROM csheets
  UNION all
  SELECT MAX(sheetid) s FROM queueitems
) as t

Explain enter image description here So question is which one better in terms of speed?

No correct solution

OTHER TIPS

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 .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top