I want to SELECT
(combine) records from multiple tables with the same schema. This is the query that I use:
SELECT visitor_name, in_time, out_time, blacklist FROM visitor_archive_2012 UNION
SELECT visitor_name, in_time, out_time, blacklist FROM visitor_archive_2013 UNION
SELECT visitor_name, in_time, out_time, blacklist FROM visitor_archive_2014 UNION
SELECT visitor_name, in_time, out_time, blacklist FROM visitor_archive_2015
I am quite certain there is a less redundant and verbose way to write this query. The schema for each of the table is exactly the same. This is in MySQL 5.6
UNION ALL
(I suppose there are no duplicate rows in these tables). It's probably going to improve performance a lot.SELECT * FROM visitor_archive_2012 UNION SELECT * FROM visitor_archive_2013 UNION SELECT * FROM visitor_archive_2014
?