MySQL查詢 條件

2021-10-06 03:09:51 字數 2106 閱讀 4410

優先順序(優先順序從左至右)

select

*from 表名;

在select後面列前使用distinct可以消除重複的行

語法如下:

select

*from 表名 where 條件

0;

查詢姓劉的學生

select

*from student where name like

'黃%'

查詢姓黃並且名字是乙個字的學生

select

*from student where name like

'黃_'

查詢姓黃或者姓劉的學生

select

*from student where name like

'黃%'

or name like

'劉%'

查詢編號是1或3或8的學生

select

*from student where id in(1

,3,8

);

查詢學生編號是3至8的學生

select

*from student where id between

3and

8;

查詢學生是1至5的男生

select

*from student where id between

1and

5and gender=

1;

注意:如果邏輯語中的and和範圍查詢中的and同時有時,記住:從左往右,發現between開始,往右的第乙個and與between組成範圍查詢,其餘的and才是邏輯語。

查詢沒有填寫位址的學生

select

*from student where hometown is

null

;

查詢有填寫位址的學生

select

*from student where hometown is

notnull

;

查詢填寫了位址的女生

select

*from student where hometown is

notnull

and gender=

0;

注:

null是真正的空的,不佔記憶體,故不能用=對其進行判斷;只能採用is null 或者 is not null 進行判斷

''是空字串,占用記憶體的

mysql查詢條件 Mysql查詢條件的使用

mysql查詢條件的使用 方法 解釋 gt 大於 gte 大於等於 lt 小於 lte 小於等於 例如 article article.objects.filter id gt 5 startswith 以指定某個字串開始,大小寫敏感 istartswith 以指定某個字串開始,大小寫不敏感 end...

mysql條件查詢

語法 select 查詢列表 from 表名where 篩選條件 分類 一.按條件表示式篩選 條件運算子 不等於 二.按邏輯表示式篩選 邏輯運算子 and or not 三.模糊查詢 like between and in is null 四.排序查詢 語法 select 查詢列表 from 表 w...

MySQL 查詢條件

使用where子句對錶中的資料篩選,結果為true的行會出現在結果集中 語法如下 select from 表名 where 條件 例 select from students where id 1 where後面支援多種運算子,進行條件的處理 比較運算子 邏輯運算子 模糊查詢 範圍查詢 空判斷等於 ...