1
I’m trying to bring all the records of a table by taking the last change so I used the MAX() function but it’s not returning any results.
These are my terms:
SELECT DISTINCT
U.USS_CODIGO,
T.CON_CODIGO,
t.CON_SEQUENCIA,
t.PLA_NUMERO,
T.PPC_DT_ALT,
t.PDT_CODIGO,
t.PPC_DT_VIGENCIA,
T.PPC_VAL_MENSALIDADE,
t.PPC_IDADE_MIN
FROM preco_produto_contrato t,
CONTRATANTE C,
USUARIO U
WHERE T.PPC_DT_ALT = (SELECT MAX(T.PPC_DT_ALT)
FROM preco_produto_contrato t
WHERE T.con_codigo = c.con_codigo
AND t.PPC_DT_EXC IS NULL
AND U.CON_CODIGO = C.CON_CODIGO
AND U.CON_CODIGO = T.CON_CODIGO
AND c.con_dt_exc IS NULL
AND t.pla_numero in (105)
AND t.con_sequencia = c.con_sequencia)
Friend, add more information such as table structure, data example, expected result... And the complete select.
– Emerson JS
SELECT DISTINCT U.USS_CODIGO, T.CON_CODIGO, t. CON_SEQUENCIA,t. PLA_NUMERO, T.PPC_DT_ALT, t. PDT_CODIGO,t. PPC_DT_VIGENCIA,T.PPC_VAL_MENSALIDADE, t. PPC_IDADE_MIN 
FROM preco_produto_contrato t, CONTRATANTE C, USUARIO U
WHERE T.PPC_DT_ALT = (SELECT MAX(T.PPC_DT_ALT)FROM preco_produto_contrato t
 WHERE T.con_codigo = c.con_codigo
 AND t.PPC_DT_EXC IS NULL
 AND U.CON_CODIGO = C.CON_CODIGO
 AND U.CON_CODIGO = T.CON_CODIGO AND c.con_dt_exc IS NULL AND t.pla_numero in (105) AND t.con_sequencia = c.con_sequencia)
– Alan Darold
Friend, when it is necessary to add more information in your question you can edit it. In this case the SELECT informed in your comment should be added in your question. I have already provided the edit. Once a moderator approves the SELECT will appear in the body of the question.
– Emerson JS
The alias of the preco_product_contact table cannot be the same , in the case "t" for the two instances of the table , select main and sub , exchange the of the sub for something like "t2" .
– Motta
uses a
order by desc
.– Marconi