加入两个表并仅在数据与另一个表

时间:2017-10-06 15:15:13

标签: sql sql-server

我有两张桌子:

 Tbl1 
 AuthID         ClientID          ClientNote
 1              12                First Appointment
 2              13                First Appointment


 tbl2
 EligID         ClientID          TypeA          DateA
 1              12                1              12/30/2015
 2              12                2              5/30/2016
 3              13                1              2/13/2016
 4              13                2              7/30/2016

我只想从tbl1中选择TypeA = 1DateA is between 01/01/2016 and 06/30/2016 tbl2的客户。

1 个答案:

答案 0 :(得分:3)

SELECT tbl1.*
  FROM tbl1
  INNER JOIN tbl2 ON tbl1.ClientID = tbl2.ClientID
WHERE tbl2.TypeA = 1 AND tbl2.DateA BETWEEN '2016-01-01' AND '2016-06-30'

应该完成你想要的工作。