MySQL資料庫查詢操作

2021-07-10 15:09:39 字數 1207 閱讀 9171

1、選擇特定的字段

select id,name,password from user;   //查詢特定字段,id,name,password順序可以隨意

select*from user;   //查詢所有字段

2、字段別名:用空格或as

select id '學號',name '姓名',password '密碼' from user;

select id as '學號',name as '姓名',password as '密碼' from user;

3、distinct關鍵字,去除重複的值(多字段時需要所有字段同時相同才會認為是重複)

select distinct age from user;

4、使用where條件查詢

5、查詢空值null

select*from user where name is null;

select*from user where name is not null;

6、between and用法

select*from user where id between 3 and 5;

7、in 的用法

select*from where id in(1,3,5);

8、like關鍵字用法,模糊查詢,text型別不能用

select*from user where name like '%s%';

select*from user where name like '%s%'

or name like '%b%';

//查詢name裡面包含字母s的資料,%表示任意多個字元

也可以用正規表示式:(不建議用)

select*from user where name regexp '.*s.*';

select*from user where name regexp '(.*s.*)|(.*5.*)';

//包含s或5

9、使用order by對查詢結果排序

select*from user order by 欄位名 desc;   //desc表示降序,預設公升序(asc)

10、使用limit限定輸出個數(分頁實現)

select*from user order by id limit 0,2;

select*from user order by id limit 5;   //相當於0,5,從0開始取5個

mysql 初級操作 查詢資料庫時間

然後在my.ini檔案中的 mysqld 下面一行新增 skip grant tables 加上這句話 1 最簡單的 create table t1 id int not null,name char 20 2 帶主鍵的 a create table t1 id int not null prima...

mysql資料庫操作 SQL查詢語言

sql structured query language ddl create drop alter dml insert delete udpate dql select dcl grant revoke 刪除和建立資料庫 drop database if exists company crea...

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

查詢命令集合 資料庫基礎查詢 以單錶資料查詢所有資料 select from table 查詢表中所有資訊 select id from table select id name from table 查詢表中指定的字段查詢 資料庫條件查詢 以某些資料作為條件進行查詢符合條件的資料 select f...