資料庫DQL語句

2021-09-12 17:51:10 字數 822 閱讀 9653

誰心中無悔,敬勇敢一杯.

1.單純的查詢

單錶查詢

select * from users;

單錶查詢指定列

select user_id,username,password from users;

指定查詢條件

select * from users where user_id = 1;

2.限制查詢條數(分頁)

limit限制查詢數目

select * from users limit 5;

查詢前5條記錄

select * from users limit 4,5;

從第4條記錄往後查詢5條記錄,不包含第4

3.不重複查詢(distinct)

查詢指定列的所有不重複值

select distinct type from users;

4.查詢記錄排序(order by)

按username排序顯示,limit應該放在order  by 的後面,預設公升序

select username from users order by username limit 5;

按降序輸出

select username from users order by username desc limit 5;

資料庫DQL語句

資料庫dql語句就是資料庫查詢語句 主要關鍵字 select 格式 select 欄位名 from 表名 where 條件 只是平常查詢不加條件可以不寫where 在用全部欄位名的情況下可以這樣 select from 表名 欄位名可以這樣用 使用別名表示學生分數。mysql select name...

資料庫DQL(更新中)

1 刪除 語法 1 delete from 表名 where expression 1 語法 1 select from 表名 表示所有字段 2 select distinct 字段 from 表名 distinct 去重 3 select 欄位1 as 別名2 欄位2 as 別名1 from 表名...

資料庫 DQL 基礎查詢

dql data query languge select 查詢列表 from 表名 特點 查詢的結果集 是乙個虛擬表 select後面跟的查詢列表,可以有多個部分組成,中間用逗號隔開 例如 select 欄位1,欄位2,表示式 from 表 查詢列表可以是 字段 表示式 常量 函式等 查詢單個字段...