mysql資料查詢之子查詢

2021-08-18 13:31:52 字數 825 閱讀 7360

子查詢概念:

sub query

select

select

(1)標量子查詢 where 之後寫 = ,確定某乙個值

select

*from

student

where

c_id = (

select

idfrom

class

where

grade =

"pm3.1"

);(2)列子查詢    where 之後 寫 in,是一列的所有值

select

*from

student

where

c_idin(

select

idfrom

class);

(3)行子查詢    兩點確定一條直線 ,where之後放兩個值,或者直接用max() 或 min()

(4)錶子查詢比較特殊,查詢內容放在from之後,查詢得到乙個表,最好再有個別名

-- 錶子查詢

select

*from

(select

*from

student

order

byheight

desc)as

student

group

byc_id;

(5)exists子查詢,放在where之後

select

*from

student

where

exists

(select

*from

class);

mysql之子查詢

所謂子查詢,就是指在乙個查詢之中巢狀了其他的若干查詢,通過子查詢可以實現多表查詢,該查詢語句中可能包含in,any,all和exists等關鍵字,除此之外還可以包含比較運算子,子查詢經常出現在where和from字句中。where字句中的子查詢 該位置處的子查詢一般返回單行單列,多行單列,單行多列資...

MySQL 之子查詢

定義 子查詢指乙個查詢語句巢狀在另乙個查詢語句內部的查詢,這個特性從 mysql4.1 開始引入,在 select 子句中先計算子查詢,子查詢結果作為外層另乙個查詢的過濾條件,查詢可以基於乙個表或者多個表。子查詢中常用的操作符有 any some all in 和 exists。子查詢可以新增到 s...

MySQL資料查詢

1.基本查詢語句 select語句是最常用的查詢語句,它的使用方式有些複雜,但功能卻相當強大。select selection list 要查詢的內容,選擇哪些列 from資料表名 制定資料表 where primary constraint 查詢時需要滿足的條件,行必須滿足條件 2.單錶查詢 單錶...