I'm new to Sql and can't seem to find an answer anywhere!...
I have a table "a" that contains a column "table_name" with the name of another table "b".
I would like to query the columns in table "a" and add an extra column with a count of the rows in table "b".
Something along these lines:
SELECT *, (SELECT COUNT(*) FROM a.table_name) AS num_rows FROM a;
Unfortunately, I can't reference a table in the "FROM" clause like this. How can I go about this?
Thanks in advance!
UPDATE
Just to clarify, I want all the rows in table "a" with an added column containing the row count of table "b": the name of table "b" is in column "table_name" in table "a".