1.查詢所有資料
select
*from 表名;
2.條件查詢select
*from 表名 where 條件;
3.查詢部分字段select 欄位1
,欄位2...
.from 表名 where 條件;
別名查詢 as
列別名,就是給字段起乙個別名,方便後面操作和檢視
別名as 可以省略 引號可以不加
查詢user表中 id為2 的 uname 姓名
select uname 姓名 from
user
where id=
"2";
去重複值 distinct
select
distinct
(字段)
from 表名;
查詢結果是表示式(運算查詢)
select 欄位+值 from 表名;
關鍵字
說明between…and…
求某一區間的值
in(set)
滿足set集合中任意條件
like
模糊查詢,like 「% _」 %:任意字元 _:乙個佔位符
is null
判斷是否為空
and多個條件同時成立or或
not不是
MySQL DQL查詢資料
查詢表中所有的資料列結果,採用 符號 select from student 效率低,不推薦 可指定查詢的結果資料列 select studentno,studentname,phone from student 如區分連線查詢時兩個同名的字段 select s.studentno,studentn...
MySQL DQL 多表查詢
create table stu id int primary key auto increment name varchar 20 gender varchar 20 math double insert into stu values null,zhangsan male 89.5 null,l...
MySQL DQL聯合查詢
union 聯合 合併 將多條查詢語句的結果合併成乙個結果 查詢語句1 union 查詢語句2 union.要求多條查詢語句的查詢列數是一致的 要求多條查詢語句的每一列的型別和順序最好一致 union自動會去重,如果使用union all可以包含重複項 案例 查詢部門編號 90或郵箱包含a的員工資訊...