資料庫mysql基礎查詢之條件查詢

2022-06-22 23:54:09 字數 961 閱讀 9788

有時候,我們想查詢出特定條件的資料,那該如何查詢呢?

答案是使用where關鍵字

我們還是以如下的表為例:

where關鍵字後面可以新增條件表示式。

舉例子:上表中,我們要查詢出last_name為 k_ing的資料

select * from employeeswhere last_name = 'k_ing'

通過where後面的條件,我們既可以查詢出last_name = 'k_ing'的資料了

在mysql中,條件查詢語句有哪些呢?

a:篩選條件為條件表示式 >  =   <=  <>

b:  篩選條件為邏輯表示式:and(&&)  or(||)  not(!)

c:模糊查詢:like (一般和萬用字元使用,%表示任意多個字元,包含0個。_任意單個字元)

between and (閉區間,不可顛倒順序,如between 100 and 120 和

between 120 and 100是不一樣的, 後者不會報錯,但是無查詢結果)

in  (用於判斷某個字段是否在列表中, 列表中的字段型別必須一致,且列表中不能用萬用字元)

is null | is not null(要十分注意,判斷是否為null值,要用 is null 或者 is not null ,不能用=null或 <>null)

擴充套件:<=>(安全等於),不僅可以用於null,也可以用於正常的值。缺點是可讀性較差。注意:沒有這種寫法。

MySQL資料庫必備之條件查詢語句

目錄 select 查詢列表 from 表名where 篩選表示式 條件運算子 條件運算子不能判斷null。在employees表中篩選工資大於12000的員工的所有資訊 select from employees where salary 12000 邏輯運算子 and,or,not 用於連線條件...

mysql分頁和條件查詢 資料庫 條件查詢和分頁

productdao dao newproductdao 目的 就是想辦法封裝乙個pagebean 並返回 pagebean pagebean newpagebean 1 當前頁private int currentpage pagebean.setcurrentpage currentpage 2...

資料庫 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 ...