I am trying to learn SQL and currently I’m learning about the COUNT function. I want to test pulling data from multiple tables and i want to return a result set like:
| tablename | row_count |
| Computers | 2000 |
| Buildings | 37 |
So far I haven’t figured out a way to pull the info and make a view like this.
Use a union and a count(*) with a (constant) label:
Note that using
union all(instead of justunion) means that rows returned will stay in the order they are selected in the query.