I have a Database with two tables:
subscriber_mm
uid_local | uid_foreign | uid_partner
7 |2 |0
7 |4 |0
2 |1 |0
2 |2 |0
5 |1 |0
5 |3 |0
partner_mm
uid_local | uid_foreign | uid_partner
7 |1 |1
My goal is to count the total number of rows by uid_local from both tables example:
count both tables by uid_local = 7
result: 3
example:
count both tables by uid_local = 2
result: 2
This is my solution (not the best) without the WHERE statement
SELECT sum(
ROWS ) AS total_rows
FROM (
SELECT count( * ) AS ROWS
FROM partner_mm
UNION ALL
SELECT count( * ) AS ROWS
FROM subscriber_mm
) AS u
how can i implement the WHERE statement?