0

Currently I've this query:

SELECT l.klantId,
       bh.rechten,
       kg.voornaam,
       kg.achternaam,
       kg.woonplaats,
       kg.telefoonnr,
       og.klantbericht,
       s.klantstatus
FROM   login l
       INNER JOIN klantGegevens kg
               ON l.klantId = kg.klantid
       INNER JOIN bevoegdheden bh
               ON l.rechten = bh.id
       INNER JOIN orderGegevens og
               ON og.loginNr = l.klantid
       INNER JOIN status s
               ON s.id = og.klantstatus
WHERE  l.klantid = 1 

enter image description here

I only want to receive the last ordernr from a klantid. What's the right way to do this. I've already tried this with "last()" but that doesn't work.

Thankss

Pரதீப்
  • 91,748
  • 19
  • 131
  • 172
Jenssen
  • 1,801
  • 4
  • 38
  • 72

2 Answers2

3
select top 1 
       l.klantId, bh.rechten, kg.voornaam, kg.achternaam, kg.woonplaats, kg.telefoonnr, og.klantbericht, s.klantstatus 
from login l 
inner join klantGegevens kg on l.klantId=kg.klantid 
inner join bevoegdheden bh on l.rechten=bh.id 
inner join orderGegevens og on og.loginNr=l.klantid 
inner join status s on s.id=og.klantstatus 
where l.klantid=1 
order by ordernr desc
juergen d
  • 201,996
  • 37
  • 293
  • 362
  • I wonder, how a lot? I use "sql server select last record" and find this on TOP 1:http://stackoverflow.com/questions/177323/how-to-read-the-last-row-with-sql-server – tjeloep May 28 '15 at 00:47
0

T-SQL: use TOP 1

PL/SQL: use ROWNUM <= 1

MySQL: use LIMIT 1

Riad Baghbanli
  • 3,105
  • 1
  • 12
  • 20