検索
ホームページデータベースmysql チュートリアルページングに MySQL LIMIT、OFFSET を使用しますか?

使用 MySQL LIMIT、OFFSET 进行分页?

まず、いくつかのレコードを含むテーブルを作成する必要があります。次に、次の助けを借りてページネーションを使用します。 リミットとオフセット。

CREATE コマンドを使用してテーブルを作成します。クエリは次のとおりです。 -

mysql> CREATE table limitoffsetDemo
-> (
-> id int,
-> FisrtName varchar(200)
-> );
Query OK, 0 rows affected (0.45 sec)

テーブルを作成した後、INSERT コマンドを使用してレコードを挿入します。

レコードの挿入

mysql> INSERT into limitoffsetDemo values(1,'John');
Query OK, 1 row affected (0.11 sec)

mysql> INSERT into limitoffsetDemo values(2,'Bob');
Query OK, 1 row affected (0.16 sec)

mysql> INSERT into limitoffsetDemo values(3,'David');
Query OK, 1 row affected (0.13 sec)

mysql> INSERT into limitoffsetDemo values(4,'carol');
Query OK, 1 row affected (0.19 sec)

mysql> INSERT into limitoffsetDemo values(5,'Taylor');
Query OK, 1 row affected (0.10 sec)

mysql> INSERT into limitoffsetDemo values(1,'John');
Query OK, 1 row affected (0.24 sec)

mysql> INSERT into limitoffsetDemo values(7,'Smith');
Query OK, 1 row affected (0.13 sec)

mysql> INSERT into limitoffsetDemo values(8,'John');
Query OK, 1 row affected (0.12 sec)

mysql> INSERT into limitoffsetDemo values(9,'Johnson');
Query OK, 1 row affected (0.11 sec)

mysql> INSERT into limitoffsetDemo values(10,'Jason');
Query OK, 1 row affected (0.08 sec)

mysql> INSERT into limitoffsetDemo values(11,'Bk');
Query OK, 1 row affected (0.17 sec)

レコードを挿入した後、次のコマンドを使用して、テーブルにあるレコードの数を確認できます。 コマンドを選択します。クエリは次のとおりです -

mysql> SELECT * from limitoffsetDemo;

上記のクエリを実行すると、次の出力が得られます

+------+-----------+
| id   | FisrtName |
+------+-----------+
| 1    | John      |
| 2    | Bob       |
| 3    | David     |
| 4    | carol     |
| 5    | Taylor    |
| 1    | John      |
| 7    | Smith     |
| 8    | John      |
| 9    | Johnson   |
| 10   | Jason     |
| 11   | Bk        |
+------+-----------+
11 rows in set (0.00 sec)

現在、レコードは 11 件あります。制限とオフセットを使用してページネーションを設定するには、次のコマンドを適用します。 構文 -

SELECT * from yourTableName limit value1,value2;

上記のクエリでは、value1 はレコードを表示する必要がある場所を示し、value2 は表示する必要があるレコードの数を示します。 記録。

ここで、上記のクエリを適用して次のような結果を取得します -

mysql> SELECT * from limitoffsetDemo limit 7,4;

以下は出力です

+------+-----------+
| id   | FirstName |
+------+-----------+
| 8    | John      |
| 9    | Johnson   |
| 10   | Jason     |
| 11   | Bk        |
+------+-----------+
4 rows in set (0.00 sec)

以上がページングに MySQL LIMIT、OFFSET を使用しますか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明
この記事はtutorialspointで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。
MySQLで既存のビューをドロップまたは変更するにはどうすればよいですか?MySQLで既存のビューをドロップまたは変更するにはどうすればよいですか?May 16, 2025 am 12:11 AM

todropaviewinmysql、 "dropviewifexistsview_name;" andtomodifyaviewを使用して、 "createorreplaceviewview_nameasselect ..."を使用します

MySQLビュー:どのデザインパターンを使用できますか?MySQLビュー:どのデザインパターンを使用できますか?May 16, 2025 am 12:10 AM

mysqlviewscanefectiveativeativeizedesignpatternslikeadapter、decorator、factory、andobserver.1)adapterpatternadaptsdatafromdifferenttablesintoaunifiedview.2)decoratorpatternenhancesdatawithedfieldsfieldsiffieldsiffieldsiffiedを

MySQLでビューを使用することの利点は何ですか?MySQLでビューを使用することの利点は何ですか?May 16, 2025 am 12:09 AM

viewsinmysqlarebenefentialforsimprifiningcomplexqueries、拡張セキュリティ、ダタコンシーニング、および最適化されたパフォーマンスを保証する1)itsmplifyififycomplexqueriesbyencapsulsingthemintoreusableviews.2)viewsencurationecuritybycontrollingcescesces.3)

MySQLで簡単なビューを作成するにはどうすればよいですか?MySQLで簡単なビューを作成するにはどうすればよいですか?May 16, 2025 am 12:08 AM

to CreateAsimpleviewinmysql、usethecreateviewstatement.1)DefinetheTheTheThecreateview_nameas.2)SpecifyTheSelectStatementtatementtatementtatementtatementtatementtatementedeSireddata.3)

MySQLはユーザーステートメントの作成:例と一般的なエラーを作成しますMySQLはユーザーステートメントの作成:例と一般的なエラーを作成しますMay 16, 2025 am 12:04 AM

tocleateusersinmysql、usethecreateuserstatement.1)foralocaluser:createUser'localuser '@' localhost'identifidedifiedifiedified 'securepassword';

MySQLでビューを使用することの限界は何ですか?MySQLでビューを使用することの限界は何ですか?May 14, 2025 am 12:10 AM

mysqlviewshavelimitations:1)supportallsqloperations、制限、dataManipulationswithjoinsorubqueries.2)それらは、特にパフォーマンス、特にパルフェクソルラージャターセット

MySQLデータベースのセキュリティ:ユーザーの追加と特権の付与MySQLデータベースのセキュリティ:ユーザーの追加と特権の付与May 14, 2025 am 12:09 AM

reperusermanmanagementInmysqliscialforenhancingsecurationsinginuring databaseaperation.1)usecreateusertoaddusers、指定connectionsourcewith@'localhost'or@'% '。

MySQLで使用できるトリガーの数にどのような要因がありますか?MySQLで使用できるトリガーの数にどのような要因がありますか?May 14, 2025 am 12:08 AM

mysqldoes notimposeahardlimitontriggers、しかしpracticalfactorsdeTerminetheireffectiveuse:1)serverconufigurationStriggermanagement; 2)complentiggersincreaseSystemload;

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

WebStorm Mac版

WebStorm Mac版

便利なJavaScript開発ツール

SublimeText3 Linux 新バージョン

SublimeText3 Linux 新バージョン

SublimeText3 Linux 最新バージョン

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)