應用場景:要顯示的數據,一頁顯示不全,需要分頁提交sql請求
特點:要將limit放在查詢語句的最後
語法
select 查詢列表
from 表
【join type】join 表2
on 連接條件
where 篩選條件
group by 分組字段
having 分組後的篩選
order by 排序的字段
limit 【offset】,size;
offset要顯示的條目的起始索引(起始索引從0開始)可省略
size 要顯示的條目個數
查詢前五條員工信息
select * from employees
limit 0,5;
查詢第11條到第25條員工信息
select * from employees limit 10,15;
集合查詢
一、union合併:將多條查詢語句的結果合併成一個結果
注意事項:
1.兩個查詢語句查詢的列數必須相同,而且列的屬性名必須對應相同
2.使用union進行聯合 默認會去掉重複的項,如果不想去重,則需要在union後加歌 all
查詢部門編號>90或郵箱中包含a 的員工信息
select *from employees where email like'%a%' or department_id>90
如果用上聯合查詢
select * from employees where email like'%a%'
union
select * from employees where department_id>90
如果比較複雜的話用union查詢會比較清晰
二、交集運算
語法
select * from student where sdept = 'CS'
intersect
select * from student where sage<=19;
三、差運算
select * from student where sdept = 'CS'
except
select * from student where sage<=19;
四、除運算