I have two (or three, or four…) tables which i want to select all at once to count the number of entries in all tables together.
for example if i have some tables:
‘news’, ‘articles’, ‘galleries’
in every table i have a row called like “author_id”
now, if i use following select statement:
SELECT *
FROM
news as n, articles as a, galleries as g
WHERE
n.author = 1
AND a.user = 1
AND g.uploader = 1
i only get a result if every table has at least one row with a author (or user or uploader whatever) matching ‘1’
how can i get a result even if one (or two..) tables do not contain ‘1’
Alternatively, you can combine the results of all table using
UNION ALLin a subquery. Then you can nowCOUNT()the specifiedAuthor_ID. The following query will get the total number of records of a specifiedauthor_idin ALL tables.followup question,