日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql外键约束查询语句_MySQL数据库 : 查询语句,连接查询及外键约束

發布時間:2024/9/18 数据库 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql外键约束查询语句_MySQL数据库 : 查询语句,连接查询及外键约束 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

查詢指定字段? ? ? ? select 字段1,字段2 from 表名;

消除重復行(重復指的是結果集中的所有完全重復行)? ? ? ? ? ? ?select distinct 字段1,字段2... from 表名

比較運算符(< > != = )? ? ? ? ? ? select * from 表名 where id>4

邏輯運算符(and or not in)? ? ? ? ? ? select * from 表名 where id>4(條件1) and gender=1(條件2);

模糊查詢(like %任意多個字符 _任意一個字符)? ? ? ? ? ? select * from 表名 where name like '馬%';

范圍查詢(in between...and...)? ? ? ? ? ? ? ? ? ?select * from 表名 where id in(1,2,3); 查詢id是1,2,3的行(非連續)

select * from 表名 where id between 1 and 5;(查詢id 1到5 的行,連續)

判空(is null) (非空 is not null)? ? ? ? ? ? ? ? ?select * from 表名 where 條件 is null;

優先級 (小括號,not,比較運算符,邏輯運算符(and比or先運算))

聚合函數

(count:求總行數)? ? ? ? ? ? ?select count(*) from 表名 where...

(max,min:最大值最小值)? ? ? ? ? ? ? select max(id) from 表名 where...

(sum,avg:求和求平均值)? ? ? ? ? ? ? select sum(id) from 表名 where...

分組(group by)? ? ? ? ? ? ? ? ? select gender count(*) from 表名 group by gender;(按性別分組并分別統計總數)

對分組結果進行篩選? ? ? ? ? ? ? ? (having) select gender count(*) from 表名 group by gender having gender=0;

where 是對 from 后的原始表進行數據篩選,having 是對group by 的結果進行篩選.

排序(order by默認升序asc降序desc)? ? ? ? ? ? ? ? ? ?select * from 表名 where 條件 order by id desc;

分頁(limit)select * from 表名 where 條件 limit 從第幾條數據開始,獲取多少條數據

完整select語句關鍵字順序:

select distinct *

from 表名 inner(left,right) join 表名 on 關系

where ...

group by ...

order by ...

limit start,count

外鍵約束 創建表的時候 最后添加? ? ? ? ? ? ? foreign key(約束字段) references 表名(字段名)

新建外鍵? ? ? ? ? ? ? ? ? ? alter table 表名 add constraint 外鍵名 foreign key(字段) references 外鍵表名(字段)

內連接查詢(inner join 連接表名 on 表名.字段=連接表名.字段) ps:兩張表必須要有一種關系

左連接(left join 以左表為準,左表數據全部顯示) 右連接同理(right join)

總結

以上是生活随笔為你收集整理的mysql外键约束查询语句_MySQL数据库 : 查询语句,连接查询及外键约束的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。