getting the row count of a UNION query
getting the row count of a UNION query
От:
Lonni J Friedman <netllama@gmail.com>
Дата:
Greetings, I've got a bunch of tables with the same schema, that I'm accessing via a UNION query. However, I'd like to get the count of returned rows from this query. The best that I've been able to come up with at this point is the following: SELECT sum(counter) FROM ((select count(id) as counter from a0 ) UNION ALL (select count(id) as counter from b0) UNION ALL (select count(id) as counter from c0)) as foo; From what I'm reading this is inefficient. Is there a better way to get the total row count without resorting to executing each of the subqueries separately and summing their rows? thanks!