`
2014马年
  • 浏览: 118866 次
  • 性别: Icon_minigender_1
  • 来自: 晋中
社区版块
存档分类
最新评论

mysql 表连接

阅读更多

 

 首先有下面的数据库

A 表

id name

1 hello

2 world

 

B 表

aid book flag

1  mysql 0

1 android 0

2 mysql 1

2 mysql 0

2 android 0

 

 

下面开始进行几种查询

 

1.inner join

 

select * from a,b where a.id=baid;
select * from a inner join b on a.id=b.aid;

 两种查询是等价的

 

 

2.左右连接

 

  A   left   join   B   的连接的记录数与A表的记录数同  
  A   right   join   B   的连接的记录数与B表的记录数同    
  A   left   join   B   等价B   right   join   A  

select * from A left join B on A.id = B.aid

 

 3.查处不连接后不重复的数据

 

select * from A left join B on A.id = B.aid
select *,count(distict A.id) from A left join B on A.id = B.aid group by A.id

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics