zoro17
Goto Top

MySQL - Anzahl Records - Limit

Hallo zusammen,
habe eine kurze Frage zu MySQL und der Limit Option:
Wenn ich einen SQL-Befehl in MySQL ohne Limit Begrenzung absetze, bekomme ich auch die Anzahl der gefundenen Records zurück.
Führe ich den gleichen Befehl mit Limit Option aus, bekomme ich als Anzahl der gefundenen Records den Limit-Wert zurück.

Wie schaffe ich es ohne weitere SQL-Abfrage, mit einer Limit-SQL-Abfrage die Anzahl der Records zu bekommen, die der SQL Abfrage entsprechen?

Beispiel: Die SQL-Abfrage ohne Limit ergibt z.B. 533 Treffer. Mit Limit 100 bekomme ich "100" Treffer (von eigentlich 533).
Ich brauche jedoch die Information trotz Limit-SQL-Abfrage, dass 533 Treffer da sind. Muss ich zuerst eine SQL-Abfrage ausführen,
um die eigentliche Anzahl der Records zu ermitteln. Oder ist der Wert 533 auch mit einer Limit-SQL-Abfrage zu bekommen?
Danke und Gruss.

Content-Key: 79356

Url: https://administrator.de/contentid/79356

Ausgedruckt am: 28.03.2024 um 20:03 Uhr

Mitglied: AndreasHoster
AndreasHoster 29.01.2008 um 08:52:29 Uhr
Goto Top
Aus dem MySQL Reference Manual:
A SELECT statement may include a LIMIT clause to restrict the number of rows the server returns to the client. In some cases, it is desirable to know how many rows the statement would have returned without the LIMIT, but without running the statement again. To obtain this row count, include a SQL_CALC_FOUND_ROWS option in the SELECT statement, and then invoke FOUND_ROWS() afterward:
mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name WHERE id > 100 LIMIT 10;
mysql> SELECT FOUND_ROWS();
The second SELECT returns a number indicating how many rows the first SELECT would have returned had it been written without the LIMIT clause.

=> http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#funct ...
Mitglied: zoro17
zoro17 29.01.2008 um 09:27:11 Uhr
Goto Top
Hallo AndreasHoster,
das ist genau das, was ich gesucht habe. Werde es ausprobieren und Rückmeldung geben.
Vielen Dank. Gruss.
Mitglied: zoro17
zoro17 29.01.2008 um 10:35:39 Uhr
Goto Top
Wenn man begreift, dass da ein Array zurückkommt, klappts.
Danke nochmal.