mysql 資料庫基礎查詢操作命令

2021-09-13 17:56:14 字數 1789 閱讀 2200

查詢命令集合

- 資料庫基礎查詢

-以單錶資料查詢所有資料

select * from table; //查詢表中所有資訊

select id from table;

select id ,name from table; // 查詢表中指定的字段查詢

- 資料庫條件查詢

-以某些資料作為條件進行查詢符合條件的資料

select * from tablewhere條件字段=『需要檢索條件』;

select * from table where table.a is null;//查詢條件為空的資料

select * from table where table.a > 100 or table.b >30;// 兩者條件有乙個滿足即可

select * from table where table.a >100 and table.b>30;// 兩者條件都要滿足

- 資料庫排序查詢

-查詢資料資訊以什麼條件進行排序,公升or 降

select * from tablewhere條件字段=『需要檢索條件』 order by id desc/asc

- 資料庫分組查詢

select * from tablewhere條件字段=『需要檢索條件』 group by id

- 資料庫分頁查詢

select * from table where id >10000 limit 1000,10

- 資料庫連線查詢

– 交叉連線

select * from table_a cross join table_b;

– 內連線

select * from table_a inner join table_b;

select * from table_a inner join table_b on b_id = id;

select * from table_a inner join table_b on table_a.b_id = table_b.id;

select * from table_a as s inner join table_b c on s.b_id = c.id;

select * from table_b c inner join table_a as s on s.b_id = c.id;

select * from table_b c inner join table_a as s where s.b_id = c.id;

select * from table_a as s left join table_b c on s.b_id = c.id;

select * from table_a as s right join table_b as c on s.b_id = c.id;

select * from table_b as c left join table_a as s on s.b_id = c.id;

– 自然內連線

select * from table_a natural join table_b;

– using關鍵字

select * from table_a left join table_b using(b_id);

- 資料庫子查詢

MySQL資料庫查詢操作

1 選擇特定的字段 select id,name,password from user 查詢特定字段,id,name,password順序可以隨意 select from user 查詢所有字段 2 字段別名 用空格或as select id 學號 name 姓名 password 密碼 from ...

資料庫 mysql基礎操作之輸入查詢

mysql uroot p 123456mysql quit檢視當前mysql的版本號及當前時間 select version current date mysql select version current date version current date 5.6.25 2018 08 08 ...

MySQL 資料庫基礎操作

1.建立資料庫 建立乙個名為db1的資料庫 create database db1 tips 當我們建立資料庫沒有指定字符集和校驗規則時,系統使用預設字符集 utf8 檢視系統支援的字符集 show charset 建立乙個使用utf8字符集的資料庫 create database test1 ch...