两种实现MySQL多表联查的方法

如果需要实现MySQL多表联查,用什么方法可以实现呢?下面就为您介绍两种常见的实现MySQL多表联查的方法,希望对您有所启迪。

MySQL多表联查例子:

下面这两个MySQL多表联查方法都可以,inner join on 更好点。表结构没贴出来,但比较好懂了。

MySQL多表联查的简单方法:

 
 
 
  1. select c.nom, e.nom   
  2. from consultant c, affaire a, besoin b, salarie sa, site s, entreprise e  
  3. where c.consultant_id=a.consultant_id and a.besoin_id=b.besoin_id and   
  4.  
  5. b.salarie_id=sa.salarie_id and ssa.site_id=s.site_id and s.entreprise_id=e.entreprise_id  

MySQL多表联查的inner join方法:

 
 
 
  1. select c.nom, e.nom  
  2. from consultant c  
  3. inner join affaire a on c.consultant_id=a.consultant_id  
  4. inner join besoin b on a.besoin_id=b.besoin_id  
  5. inner join salarie sa on b.salarie_id=sa.salarie_id  
  6. inner join site s on ssa.site_id=s.site_id  
  7. inner join entreprise e on s.entreprise_id=e.entreprise_id  
  8.  

 

 

【编辑推荐】

带您了解mysql变量

撤权并删除MySQL用户的方法

使用MySQL命令行备份及恢复数据库

MySQL root用户密码忘记的处理方法

MySQL创建函数问题的处理方法

 

THE END