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.  

LVL 1
ttist25Asked:
Who is Participating?
 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.