日期:2014-05-18  浏览次数:20448 次

高手们问个简单的问题,谁来帮小弟一把吧
表结构是这样的  
表1     父表  
table1ID     Date    
  表2   子表  
table2ID   teble1ID   text  
我怎么能把表2中tableID不重覆的对应的table1的记录查出来?    
如  
table1ID     date  
1                   2007-1-1  
2                   2007-2-1  
3                   2007-3-1    
table2ID     table1ID       text
  1                   1            
  2                   1    
3                   3  
这样的数据,查出来的结果是  
1                   2007-1-1  
3                   2007-3-1


------解决方案--------------------
select * from 表1 a
where exists (
select 1 from 表2
where table1id=a.table1id
)
------解决方案--------------------
select * from 表1
where table1ID in (select distinct table1ID from 表2)