資料庫SQL語句 四表連線(left join)

2021-09-24 02:09:21 字數 1502 閱讀 3101

left join 關鍵字會從左表 (table_name1) 那裡返回所有的行,即使在右表 (table_name2) 中沒有匹配的行。

select column_name(s)

from table_name1

left join table_name2

on table_name1.column_name=table_name2.column_name

注釋:在某些資料庫中, left join 稱為 left outer join。

select * from student      /*sno學號、sname姓名、 sbirthday出生年月、sclass班級 */

2.course表

select * from course       /*cno課程號、cname課程名、tno教工編號 */

3.score表

select * from score         /* sno學號、cno課程號、degree 成績*/

4.teacher表

select * from teacher           /*tno教工編號、tname教工姓名、t***教工性別 、tbirthday教工出生年月、prof職稱、depart教工所在單位*/

select student.sname 學生姓名,student.s*** 學生性別,student.sbirthday 學生出生年月,student.sclass 學生班級,

score.degree 成績,

course.cname 課程名稱,

teacher.tname 教工姓名,teacher.t*** 教工性別 ,teacher.prof 教工職稱,teacher.depart 教工所在單位

SQL資料庫連線語句

一般的遠端訪問的寫成這樣 data source ip initial catalog 資料庫名 userid 使用者名稱 password 密碼 本地訪問的寫成這樣 data source local initial catalog 資料庫名 userid 使用者名稱 password 密碼 如果...

資料庫表維護(sql語句)

新增字段 alter table 表名 add 欄位名 nvarchar 50 null 刪除字段 alter table 表名 drop column 欄位名 修改字段 alter table 表名 alter column 欄位名 nvarchar 50 null 重新命名表 access 重新...

民族資料庫表SQL語句

create table dbo b nation code char 2 not null primary key nation varchar 20 insert into b nation values 01 漢族 insert into b nation values 02 蒙古族 inse...