I have several tables with the same structure. How can I select SUM(field) from these tables without JOIN (just simply union the tables)?
For example, if I run:
SELECT SUM(views) FROM tb1, tb2 WHERE 1
It tells me “Column ‘views’ in field list is ambiguous”.
Is there a way to use UNION?
I think this should get you:
The reason you’re getting an error is because you’re making a Cartesian product (all rows in one table are matched to all rows in the other table), and since both tables have a
viewcolumn, it doesn’t know which you’re taking about. However, that Cartesian join will (probably) not give you the sum you’re looking for.