mysql的5中查詢子句之五limit限制查詢
阿新 • • 發佈:2019-02-17
limit 在語句最後,起到限制條目的作用。它的語法
limit [offset,]N
offset 偏移量,如果offset不寫,預設是0,N
N 取出的條目
1、取出觸發器id最高的前三個專案
mysql> select functionid,itemid,triggerid,function from functions order by triggerid desc limit 3;
2、取出觸發器id 4,5,6 高的欄目
mysql> select functionid,itemid,triggerid,function from functions order by triggerid desc limit 3,3;
3、取出每個功能裡面fuctionid最大的欄目
思路:建立臨時表,如果不夠建表,需要用到子查詢,子查詢的結果可以看成一張表
#構建臨時表
mysql> select functionid,itemid,triggerid,function from functions order by function,functionid desc;
#用子查詢
select * from (select functionid,itemid,triggerid,function from functions order by function,functionid desc) as tmp group by function;
mysql的5中查詢子句
mysql的5中查詢子句之一where條件查詢
http://blog.csdn.net/m0_37886429/article/details/73224579
mysql的5中查詢子句之二group by分組查詢
http://blog.csdn.net/m0_37886429/article/details/73276996
mysql的5中查詢子句之三having條件查詢
http://blog.csdn.net/m0_37886429/article/details/73323970
mysql的5中查詢子句之四order by排序查詢
http://blog.csdn.net/m0_37886429/article/details/73457866
mysql的5中查詢子句之五limit限制查詢
http://blog.csdn.net/m0_37886429/article/details/73481387