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

帮忙看看查询语句条件该如何写
数据表tb1


条件表tb2
Year Month
2010 01
2010 02
2011 05


如何查询tb1 里面 2010年1,2月份数据,2011年5月份数据

如果用下面这个语句肯定是错了,到时候会把2010年和2011年1,2,5月份查出来
select * from tb1
where year in (select year from tb2)
and month in (select month from tb2)

不知道有啥语句可以实现tb2的条件,因为tb2条件可能很多,我总不能一行一行的写条件吧

------解决方案--------------------
select * from tb1 A
inner join tb2 B on B.year = A.year and B.month = A.month