重新了解資料庫 聯表查詢和自連線

2021-10-23 05:04:04 字數 1118 閱讀 3917

聯表查詢分為inner join、left join、right join

left join左連線:以左表為主。結果會將左表所有的查詢資訊列出,而右表只列出on後條件與左表滿足的部分。

right join左連線:以右表為主。結果會將右表所有的查詢資訊列出,而左表只列出on後條件與右表滿足的部分。

查詢學生的學號,姓名和成績從student學生表和result成績表

inner join:

select s.id,name,score

from student as s

inner join result as r

where s.id = r.id;

left join:

select s.id,name,score

from student as s

left join result as r

where s.id = r.id;

right join:

select s.id,name,score

from student as s

right join result as r

where s.id = r.id;

查詢父子資訊:把一張表看為兩個一模一樣的表,然後就可以對錶進行其他操作了。

select a.categoryname as '父列',b.categoryname as '子列'

from category as a,category as b

where a.categoryid = b.pid;

重新了解資料庫 DQL(查詢)

dql是資料庫查詢語言,就是我們平時最常用的查詢的語句。select完整語法 select from 表名 查詢表中所有資料 select 字段,字段 from 表名 查詢指定字段 給查出的資料加內容 select concat 姓名 name as 新名字 from 表名 修改全部的查詢結果 se...

重新了解資料庫 資料庫常用基礎

關係型資料庫 sql 通過表和表之間,列和列之間的關係進行資料的儲存 非關係型資料庫 nosql not only 非關係型資料庫,物件儲存,通過物件的自身的屬性來決定 數字 字串 時間日期 show databases 檢視所有資料庫 use user 切換user資料庫 show tables ...

資料庫聯表查詢ABC

最近修改商戶後台的bug,把資料庫相關的技術學習了一遍,俺的終極目標是自己編乙個小型的資料庫,廢話說多了 直接上 case when ns plat res code.is custom reason 1 and ns bill biz msg sts 03 and ns bill biz pmt ...