SQL資料庫查詢語句問題

時間 2022-02-20 22:30:11

1樓:匿名使用者

簡單點說 inner join 就是 只把連線的表中的資料符合鏈結條件的顯示出來

leftjion 是上面的基礎上 把左邊的表上不符合鏈結條件的資料顯示出來

rightjion 是在innerjoin的基礎上把右邊表的不符合條件的資料顯示出來

還有個fulljoin 把兩邊所有的資料都列出來

2樓:匿名使用者

舉個例子:

假設a表和b表的資料是這樣的。

a b

id name  id stock

1  a 1 15

2 b 2 50

3 c

select * from a inner join b on a.id=b.id

這個語法是連線查詢中的內連線,它產生的結果是

兩個表相匹配的記錄出現在結果列表中。

根據上面的表,出現的結果是這樣的

a.id name b.id stock

1   a 1 15

2 b 2 50

----------------------------

select * from a,b where a.id=b.id

這個語法是內連線的另外一種寫法,其執行結果與inner join 一樣

--------------------------------

select * from a left/right join b on a.id=b.id

這個是外連線語法中的左外連線或右外連線

如果是左外連線的話,它將顯示a表的所有記錄,

select a.*,b.* from a left join b on a.id=b.id

查詢的結果是這樣的:

a.id name b.id stock

1   a 1 15

2 b 2 50

3 c null null

--------------------------------------------

如果是右外連線的話,它將顯示b表的所有記錄,

select a.*,b.* from a right join b on a.id=b.id

查詢的結果是這樣的:

a.id name b.id stock

1   a 1 15

2 b 2 50

3樓:匿名使用者

孰能生巧 自己多試著多在資料庫中實際運用就知道了

SQL查詢語句的問題,acess資料庫

select name,xuehao,sum chengji1 sum chengji2 sum chengji3 sum chengji4 from student group by name name是名字 xuehao是學號 chengji是成績 前提條件,每個學生的每科成績是唯一的!否則,這...

sql資料庫使用者驗證語句,SQL資料庫使用者驗證語句

sql語句 select from tablename where userid userid and userpwd userpass 要不寫在儲存過程裡 set ansi nulls on set quoted identifier on goalter procedure dbo loginp...

資料庫排序問題寫出sql語句,資料庫排序問題(寫出SQL語句)

du瓶邪 將字段依次寫在order by 後面即可 中間用逗號隔開。view plaincopy to clipboardprint?select from 表 order by time name select from 表 order by time asc name asc select fr...