I want to find the most recent edit date for tables in my database.
This is an example of the query I plan to use:
SELECT `edited` FROM `table1`
UNION SELECT `edited` FROM `table2`
UNION SELECT `edited` FROM `table3`
UNION SELECT `edited` FROM `table4`
ORDER BY `edited` DESC
LIMIT 1
It works, but I am hoping someone can provide a more performant solution.
This may run faster as it will limit each of the selects to one row instead of returning all rows from each table.
SELECT MAX(`edited`) FROM `table1`
UNION SELECT MAX(`edited`) FROM `table2`
UNION SELECT MAX(`edited`) FROM `table3`
UNION SELECT MAX(`edited`) FROM `table4`
ORDER BY `edited` DESC
LIMIT 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.