[MySQL]limitで検索結果件数を指定する
1.1件目からn件取得
書式
LIMIT 件数
使用例
SELECT ContactName,Address,City,Country FROM
Customers
ORDER BY Country DESC
Limit 3
SELECT ContactName,Address,City,Country FROM
Customers
ORDER BY Country DESC
Limit 3
SELECT ContactName,Address,City,Country FROM Customers ORDER BY Country DESC Limit 3
結果
ContactName | Address | City | Country |
---|---|---|---|
Manuel Pereira | 5ª Ave. Los Palos Grandes | Caracas | Venezuela |
Carlos Hernández | Carrera 22 con Ave. Carlos Soublette #8-35 | San Cristóbal | Venezuela |
Carlos González | Carrera 52 con Ave. Bolívar #65-98 Llano Largo | Barquisimeto | Venezuela |
2.指定件目からn件取得
書式
limit 指定件目数,件数
使用例
SELECT ContactName,Address,City,Country FROM
Customers
ORDER BY Country DESC
Limit 3,2
SELECT ContactName,Address,City,Country FROM
Customers
ORDER BY Country DESC
Limit 3,2
SELECT ContactName,Address,City,Country FROM Customers ORDER BY Country DESC Limit 3,2
結果
ContactName | Address | City | Country |
---|---|---|---|
Felipe Izquierdo | Ave. 5 de Mayo Porlamar | I. de Margarita | Venezuela |
Howard Snyder | 2732 Baker Blvd. | Eugene | USA |