Bring a record of each ID with the most recent change date

0

I'm working with Oracle database and PHP, I need to return only one product each with the most recent change date, the tables are as follows.

product

price

Ihavetriedseveralquerytypes,butIalwaysgetduplicateresults.

Andtryingtogroupwiththefollowingquery

SELECTa.CODPROD,a.DESCRICAO,b.PVENDA,b.CODPRODFROMPCPRODUTa,PCPRECObGROUPBYb.CODPROD

Igetthefollowingerror:

  

"ORA-00979: not a GROUP BY expression"

    
asked by anonymous 22.12.2016 / 13:35

1 answer

0

It's been a while since I did not use Oracle, try something like this:

SELECT a.CODPROD, a.DESCRICAO, b.PVENDA, b.CODPROD, MAX(b.DATAALTER)
FROM PCPRODUT a, 
INNER JOIN PCPRECO b ON a.CODPROD = b.CODPROD
GROUP BY a.CODPROD, a.DESCRICAO, b.PVENDA, b.CODPROD
    
22.12.2016 / 14:54