I have a table of provas
and a table of alunos
that have no direct relationship, I still have a inscrição aluno
table and a escolas
table, as follows in the modeling below:
Ineedtocreateaselecttobringhowmanystudentsfromeachschoolareenrolledineachtest.
IranintoagambiarrawithgreatcaveatsbecauseSELECT
workedperfectly:
SELECT(SELECTcount(ia.idaluno)FROMinscricaoalunoiaINNERJOINalunosaONa.idaluno=ia.idalunoWHEREa.idpessoa_juridica=e.idpessoa_juridicaANDia.idprova=p.idprova)qtd,e.nome,e.idpessoa_juridica,p.descprova,p.idprovaFROMescolaseINNERJOINprovapON1=1GROUPBYe.nome,e.idpessoa_juridica,p.descprova,p.idprovaORDERBYe.nome;
"I created a nonexistent relationship" from the school table with the test table using a INNER JOIN ON 1 = 1
, so I listed all the tests for each school if I have the following data for example:
This"nonexistent" relationship will bring me the following result:
With this I create a subquery in the data that brings me the amount of each student in each test according to the school he studies.
Now that doubt comes, is this a gambiarra? The result is satisfactory, it works, but many people do not welcome the use of the 1 = 1
artifact