0

I have a table in a Firebird 2.5 Database where I have to find out the latest entry for one specific articel no. Therefore the table has a colum "date".

I tried several queries but I always get more than 1 entry for the article no.

I used the following query:

select max(lp.datum) as Wareneingangsdatum, lp.nr, lp.artikelnr,      lp.belegnr, lf.nr, lf.name, lf.plz, lf.ort, lf.laenderkuerzelnr, lae.bezeichnung
from lagerprotokoll lp
left join waeinpos we on we.idnr = lp.belegposidnr
left join waein we1 on we1.nr = we.nr
left join liefrant lf on lf.nr = we1.lieferantnr
left join laender lae on lae.nr = lf.laenderkuerzelnr
where lp.belegtyp = 14
group by 2,3,4,5,6,7,8,9, 10
order by 1 desc

How can I achieve the result so that I can only get the latest entry for one specific article in the table.

  • Why using left join with all tables? – jophab Sep 06 '17 at 09:42
  • Please provide an example data set, the expected result and the actual result. Note that your problem probably has to do with the fact that you are not only grouping by `artikelnr`, but also by other fields. See the linked duplicate for ways to solve this. – Mark Rotteveel Sep 06 '17 at 09:48

0 Answers0