• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

SQL Query

Hey Guys,

I have two tables - tblMain and tblOT.  Both tables have LAST, FIRST, and DOB fields.  I'd like to find all of the records in tblOT that have a matching record in tblMain using LAST, FIRST, and DOB as the identifying fields.  

I know this will match on LAST:

Select * from tblOT T1 where
T1.[LAST] in (select T2.Last from tblMain T2)

But I have no idea how to match on all three fields.  

Thanks in advance for any help you can provide.  

0
ttist25
Asked:
ttist25
1 Solution
 
ssisworoCommented:
Try this :

select T1.* from tblOT T1, tblMain T2
where T1.LAST = T2.LAST and
            T1.FIRST = T2.FIRST and
             T1.DOB = T2.DOB
0
 
Om PrakashCommented:
Try:

Select T1.*, T2.* from tblMain T1
Join tblOT T2 ON T1.LAST  = T2.Last AND T1.first  = T2.first AND T1.DOB = T2.DOB

0
 
Pratima PharandeCommented:
Select LAST, FIRST,DOB from tblOT where
Exists  (select  LAST, FIRST,DOB from tblMain )
0
 
SharathData EngineerCommented:
You can try the INNER JOIN as mentioned above (or) an EXISTS clause.
SELECT * 
  FROM tblOT T1 
 WHERE EXISTS (SELECT 1 
                 FROM tblMain T2 
                WHERE T1.[LAST] = T2.[LAST] 
                      AND T1.[FIRST] = T2.[FIRST] 
                      AND T1.DOB = T2.DOB)

Open in new window

0
 
ttist25Author Commented:
This worked perfectly.  Sorry for the delay in responding.  Things got crazy here.  

Thanks again!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now