0
I have custom to use the following querie structure to return the amount of table records from my mysql database:
SELECT
(SELECT COUNT(tab1_codigo) FROM tabela1 where alguma coisa) AS total1,
(SELECT COUNT(tab2_codigo) FROM tabela2 where alguma coisa) AS total2,
(SELECT COUNT(tab3_codigo) FROM tabela3 where alguma coisa) AS total3
FROM tabela4;
"something" refers to some specific filter that I perform within each querie.
Honey works just fine! However, in order to make this querie more optimized, I tried to delimit the amount of records, staying as follows:
SELECT
(SELECT COUNT(tab1_codigo) FROM tabela1 where alguma coisa limit 50) AS total1,
(SELECT COUNT(tab2_codigo) FROM tabela2 where alguma coisa limit 50) AS total2,
(SELECT COUNT(tab3_codigo) FROM tabela3 where alguma coisa limit 50) AS total3
FROM tabela4 limit 1;
When running the querie, I realized that an error is returned because of the "limit 50" clause. Only the clause "limit 1" (inserted at the end) was accepted without errors. Could someone explain to me a little bit about how this kind of querie structure works? Is it possible for me to use the limit clause within these queries or some more appropriate means of working with this type of structure?