成都网站建设设计

将想法与焦点和您一起共享

SQL连接的几种方式

SQL连接的重要性毋庸置疑,下面就将为您介绍SQL内连接和外连接的几个例子,供您参考,希望对您学习能有所启迪。

--创建table_A 和table_B两个表

create table table_A(id int,TextcCol varchar(255))

create table table_B(id int,TextcCol varchar(255))

--插入数据   此插入方式是通过union all实现的

insert into table_B

select 2,'hello'

union ALl    --此处的union起到连接上下两个句子的作用

select 3,'world'

union ALl

select 4,'guo'

--内连接的两种方式

--第一种方式:

Select * from table_A,table_B where table_A.id = table_B.id;

--第二种方式:

Select * from table_A A inner join table_B B on A.id = B.id

--外连接 中的左右连接

select * from table_A right join table_B on table_A.id = table_B.id

select * from table_A left join table_B on table_A.id = table_B.id

【编辑推荐】

SQL select语句的处理顺序

三种SQL分页语句

修改SQL主键约束的SQL语句写法

如何定义SQL主键

SQL字段类型长度的更改方法


分享文章:SQL连接的几种方式
网站链接:https://chengdu.cdxwcx.cn/article/djjsois.html