MySQL資料庫基本用法 查詢

2021-09-28 12:36:57 字數 1326 閱讀 9697

查詢的基本語法

select * from 表名;

from關鍵字後面寫表名,表示資料**於是這張表

select後面寫表中的列名,如果是*表示在結果中顯示表中所有列

在select後面的列名部分,可以使用as為列起別名,這個別名出現在結果集中

如果要查詢多個列,之間使用逗號分隔

在select後面列前使用distinct可以消除重複的行
select distinct gender from students;
使用where子句對錶中的資料篩選,結果為true的行會出現在結果集中

語法如下:

select * from 表名 where 條件;
比較運算子

select * from students where id>3;
select * from subjects where id<=4;
select * from students where sname!='黃蓉';
select * from students where isdelete=0;
邏輯運算子

select * from students where id>3 and gender=0;
select * from students where id<4 or isdelete=0;
模糊查詢

select * from students where sname like '黃%';
select * from students where sname like '黃_';
select * from students where sname like '黃%' or sname like '%靖%';
範圍查詢

select * from students where id in(1,3,8);
select * from students where id between 3 and 8;
select * from students where id between 3 and 8 and gender=1;
空判斷

select * from students where hometown is null;
select * from students where hometown is not null;
select * from students where hometown is not null and gender=0;
優先順序

mysql資料庫基本用法

最近學習mysql,簡單的記錄一下 一 將資料表user info從資料庫db a複製到資料庫db b 注意 mysql語句是在資料庫db b中執行 1 資料庫db b中沒有資料表user info 表名可以根據需要設定,不需要跟a中表名一致 建立表b user並複製表user info的表結構,使...

MySQL資料庫基本用法

mysql u root p u 使用者名稱 h後面寫要連線的主機ip位址 u後面寫連線的使用者名稱 p回車後寫密碼 回車後輸入密碼,當前設定的密碼為toor建立資料庫 create database 資料庫名 charset utf8 刪除資料庫 drop database 資料庫名 切換資料庫 ...

MySQL資料庫的基本用法

mysql資料庫的用法 1.開啟和關閉windows服務 net start 服務名 net stop 服務名 2.登入mysql資料庫 mysql h c hello aa.sql 匯出的路徑 2.使用客戶端匯出,或者複製sql語句 6.資料匯入 1.使用dos視窗 空格 拖進來需要匯入的檔案 2...