I have about 9 tables that contain the same type of field. I would like to combine the 9 of them FIRST, and then get the distinct count of unique values in that combined column. This is what I’ve tried so far, but to no avail. I’m not also not sure this is the most efficient way to return this value?
SELECT COUNT(DISTINCT aircraft_id) FROM
(
SELECT aircraft_id FROM database.a_message UNION ALL
SELECT aircraft_id FROM database.b_message UNION ALL
SELECT aircraft_id FROM database.c_message UNION ALL
SELECT aircraft_id FROM database.d_message UNION ALL
SELECT aircraft_id FROM database.e_message UNION ALL
SELECT aircraft_id FROM database.f_message UNION ALL
SELECT aircraft_id FROM database.g_message UNION ALL
SELECT aircraft_id FROM database.h_message UNION ALL
SELECT aircraft_id FROM database.i_message
) ;
or