2021-06-05多表连接查询

create database one20210605 default charset=utf8;

use one20210605;

create table student(

sid int ,

`sname`varchar(10),

saddrress varchar (100)

);

create table course (

cid int ,          # 课程id

sid int ,          #

cname varchar(100)

);

insert into student values (1 , '关羽',"许昌"),(2 , '诸葛亮',"南阳"),(3 , '张飞',"河北"),(4 , '刘备',"四川")

(5 ,"阿斗","蜀国");

insert into course  values (101 ,1 "三百回合不累法"),(102 , 2,"劝人投降话术"),(101 , 3,"三百回合不累法"),(102 , 4 ,"劝人投降话术"),(103 ,1 "如何俘获大乔和小乔");

select * from student;

select * from course;

-- 交叉查询  (迪卡尔积查询)

select * from student , course;

select * from student , course where student.sid= course.sid;

-- 内连接

select * from student inner join course on student.sid=course.sid;

--左外链接

select * from student left join course on student.sid=course.sid;

--右外连接

select * from student right course on student.sid=course.sid;

-- 全外连接

select * from student full course on student.sid=course.sid;                                 

你可能感兴趣的:(2021-06-05多表连接查询)