码迷,mamicode.com
首页 > 数据库 > 详细

SQL exists( select 1 from

时间:2015-12-23 19:22:11      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:

use UnlockIndustry

select * from Info_Coordinate as A 
 join Info_Employee on A.EmployeeId=Info_Employee.EmployeeId  
  Where exists( select 1 from ( select EmployeeId,MAX(CreateTime) as CreateTime from Info_Coordinate  group by Info_Coordinate.EmployeeId ) as b 
     where A.EmployeeId=b.EmployeeId and A.CreateTime=b.CreateTime) 
  And Info_Employee.CompanyId=‘1306010001‘
   /*
   关联人员和地址表。  select * from info_A as A JOIN Info_B ON A.id=Info_B.id where exists() and info_B.Cid=‘‘
   */ 

  

例子:

______________________________________________________________________________

use MyMvc
select * from Info_Company
select * from Info_Empoyee
select * from Info_Empoyee left Join Info_Company on Info_Empoyee.CompanyID=Info_Company.CompanyID
select * from Info_Empoyee where exists(select 1 from Info_Company where Info_Empoyee.CompanyId=Info_Company.CompanyID)

  

技术分享

SQL exists( select 1 from

标签:

原文地址:http://www.cnblogs.com/blogs2014/p/5070684.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!