Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Ich habe folgendes SQL-Statement (vereinfacht hier dargestellt):

SELECT <feld1>, <feld2>
WHERE <feld1> = <wert>
AND <feld2> = <wert>
ORDER BY <feld1>
FETCH FIRST 5 ROWS ONLY;

Nun ist es so, die Abfrage ergibt ca. 50.000 Datensätze, von denen ich nur 5 haben möchte. Dieses Limit wird gänzlich ignoriert und trotzdem die 50.000 Datensätze gezogen. Ich habe es auch schon mit LIMIT probiert statt FETCH FIRST 5 ROWS ONLY; Ergebnis das gleiche. Als Technologie setze ich Hibernate ein. Ich logge das Statement und die Query mit.

Statement sieht so aus:

SELECT <feld1>, <feld2>
WHERE <feld1> = <wert>
AND <feld2> = <wert>
ORDER BY <feld1>
FETCH FIRST 5 ROWS ONLY;

Die von Hibernate ausgeführte Query sieht so aus:

SELECT <feld1>, <feld2>
WHERE <feld1> = <wert>
AND <feld2> = <wert>
ORDER BY <feld1>;

 

Kann mir jemand helfen?

  • Autor

Kleines Update:

Ich nutze

Query.setMaxResults()

und setze eine DB2-Datenbank ein. Trotzdem zieht die Limitierung im SQL nicht.

Dort kann ich ja im SQL nicht mit LIMIT arbeiten, sondern muss mit FETCH FIRST 5 ROWS ONLY; arbeiten.

  • Autor

@Crash2001

danke schon mal für Deine Antwort. Vor dem setMaxResult() rufe ich noch setFirstResult() auf. Ich habe eine andere Methode, die bis auf das SQL-Statement genau identisch aussieht. Ich nenne mal die andere Methode "Methode2". Diese Methode2 funktioniert mit dem Limit, meine andere Methode nicht. Obwohl sich beide Methoden nur vom Query unterscheiden.

Kleiner Nachtrag:

In Methode2 habe ich keinen Left Join, in meiner Methode1 (die setMaxResult ignoriert) schon.

Bearbeitet von Alex_winf01

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.