5
Of agreement with the documentation, Mysql does not allow the use of Subqueries in the FROM when the consultation is a view:
Subqueries cannot be used in the FROM clause of a view.
Resulting in the following error:
1349: View’s SELECT contains a subquery in the FROM clause
The following query returns the sum of the count of the records of each table:
SELECT SUM(total)
FROM (
SELECT COUNT(*) AS total
FROM tabela1
WHERE escondido='não'
UNION ALL
SELECT COUNT(*) AS total
FROM tabela2
WHERE escondido='não'
) t
Assuming 1000 records on tabela1 and 500 in tabela2, query returns 1500.
With the following amendment to the consultation, it is already possible to create the view, but the result is two rows, each with the total records of each table:
SELECT COUNT(*) AS total
FROM tabela1
WHERE escondido='não'
UNION ALL
SELECT COUNT(*) AS total
FROM tabela2
WHERE escondido='não'

SELECT Sum(total) FROM View_no_Mysql_que_nao_aceita_subquerydoes not solve your problem?– gmsantos
@gmsantos In a way it should work, but the idea is that the
viewreturn the result of theSUM()and not values to be processed.– Zuul
Without subquery I find complicated... I’ll try here with
outer join. For these and others I am leaving Mysql– gmsantos
@gmsantos Thanks for the support, I have now put a response with a solution that meets what I was looking for... I’ve been testing the subject and this way I can resolve the issue.
– Zuul