SELECT * FROM table LIMIT 5;
select * from issu_info limit 0,6
Limit 0,6
這裡是對的,顯示前6條
select * from issu_info limit 7,6;
Limit 7,6
從第8條開始取,取6條
select * from table order by rand() limit 1
這是隨機選取一個記錄,如果想提取多個就將1改為你想要的數目Top
在mysql中利用select語句的一個特性就可以很方便地實現查詢結果的分頁,select語句的文法:
SELECT [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [HIGH_PRIORITY]
[DISTINCT | DISTINCTROW | ALL]
select_expression,...
[INTO OUTFILE 'file_name' export_options]
[FROM table_references
[WHERE where_definition]
[GROUP BY col_name,...]
[HAVING where_definition]
[ORDER BY {unsigned_integer | col_name | formula} [ASC | DESC] ,...]
[LIMIT [offset,] rows]
[PROCEDURE procedure_name] ]
LIMIT子句可以用來限制由SELECT語句返回過來的資料數量,它有一個或兩個參數,如果給出兩個參數,
第一個參數指定返回的第一行在所有資料中的位置,從0開始(注意不是1),第二個參數指定最多返回行
數。例如:
select * from table LIMIT 5,10; #返回第6-15行資料
select * from table LIMIT 5; #返回前5行
select * from table LIMIT 0,5; #返回前5行
SQL在不同資料庫中查詢前幾條記錄的用法2008-03-30 上午 10:261. ORACLE
SELECT * FROM TABLE1 WHERE ROWNUM<=N
2. INFORMIX
SELECT FIRST N * FROM TABLE1
3. DB2
SELECT * ROW_NUMBER() OVER(ORDER BY COL1 DESC) AS ROWNUM WHERE ROWNUM<=N
或者
SELECT COLUMN FROM TABLE FETCH FIRST N ROWS ONLY
4. SQL SERVER
SELECT TOP N * FROM TABLE1
5. SYBASE
SET ROWCOUNT N
GO
SELECT * FROM TABLE1
6. MYSQL
SELECT * FROM TABLE1 LIMIT N
7. FOXPRO
SELECT * TOP N FROM TABLE ORDER BY COLUMN
8.postgres查詢前幾條記錄SQL
SELECT * FROM TABLE LIMIT
select id from mytable order by update_date desc limit 0,3;