MySQL中的LIMIT關鍵字可以指定輸出中傳回的記錄數。 LIMIT 子句限制要傳回的行數。可以透過以下範例來理解 -
mysql> Select * from Student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | | 125 | Raman | Shimla | Computers | | 130 | Ram | Jhansi | Computers | | 132 | Shyam | Chandigarh | Economics | | 133 | Mohan | Delhi | Computers | | 150 | Saurabh | NULL | Literature | +------+---------+------------+------------+ 7 rows in set (0.00 sec)
上面的結果集顯示表格「student_info」總共有 7 行。
但是,如果我們只想在輸出中取得前 2 行,那麼我們可以使用 LIMIT關鍵字後面跟著 2,如下 -
mysql> Select * from Student_info LIMIT 2; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | +------+---------+------------+------------+ 2 rows in set (0.00 sec)
以上是MySQL查詢中LIMIT關鍵字有什麼用?的詳細內容。更多資訊請關注PHP中文網其他相關文章!