SQL连接的几种方式


  本文标签: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