One or more queries
If you have a specific goal to perform a query to get certain information organized in a certain way, yes, the most effective way is a single query to the database that returns everything ready to use:
Inquiry
Assuming you want to query for suspeito
X:
SELECT
tp_artigo.descricao_artigo AS descricao_artigo,
processo_judicial.dt_processo AS dt_processo,
tp_situacao_processo.descricao_situacao_processo AS descricao_situacao,
processo_judicial.pdf_processo AS pdf_processo
FROM suspeito
INNER JOIN suspeito_processo ON (
suspeito_processo.cd_suspeito = suspeito.cd_suspeito
)
INNER JOIN processo_judicial ON (
processo_judicial.num_processo = suspeito_processo.num_processo
)
INNER JOIN tp_situacao_processo ON (
tp_situacao_processo.cd_situacao_processo = processo_judicial.cd_situacao_processo
)
INNER JOIN tp_artigo ON (
tp_artigo.cd_artigo = processo_judicial.cd_artigo
)
WHERE suspeito.cd_suspeito = 1
Result of the query
The query above performs a specific task which is to collect the following data for suspeito
X:
┌──────────────────┬─────────────┬────────────────────┬──────────────┐
│ descricao_artigo │ dt_processo │ descricao_situacao │ pdf_processo │
└──────────────────┴─────────────┴────────────────────┴──────────────┘
Web service or MySQL View
If the query is to get general information, ie for all
suspeito
, a
VIEW
is preferable because it becomes more practical to update in the future and also because there are no variable data to consider.
If the query is as it was understood, query certain information of suspeito
X, then the web service will be the path to take because of the logic and validations to make to the data. / p>
Note: You can also have a VIEW
to receive parameters, but for this you need to create a MySQL function. Too much work and code to keep, where it is also preferable here to keep the query in web service .