troubleshooting Question

2 Table SQL Join with Min/Max DateTime

Avatar of Member_2_1242703
Member_2_1242703 asked on
Microsoft SQL ServerMicrosoft SQL Server 2008SQL
11 Comments1 Solution400 ViewsLast Modified:
I would like 2 join two table from the same database.

Table1 has the following columns:

Table2 has the following columns
FirstName, LastName, CARDNO2, Super

Table1 will have many entries of the same CARDNO with different values for TZDT which is Date/Time
Table2 will just have one entry for CARDNO2

Here is what I would like to display:

Table2.FirstName +' '+ Table2.LastName AS FLNAME
WHERE Table1.TZDT = '12/20/2009'
AND Table2.Super = 'Smith,Joe'
AND Table1.CARDNO = Table2.CARDNO2

For example....

TZDT                             CARDNO
11/10/2009 8:15:00    72654
11/15/2009 8:15:00    72654
12/20/2009 8:15:00    72654
12/20/2009 9:20:00    72654
12/20/2009 9:45:00    72654
12/20/2009 10:30:00  72654
12/31/2009 8:15:00    72654

FirstName  LastName  CARDNO2 Super
Mike             Jones          72654         Smith,Joe
Steve           Smith           00001         Barnes,Rick
Chris           Brown          00002         Brown,Mac
James        Miller            00003         Applewhite,Major

The query should return
Mike Jones       12/20/2009 8:15:00       12/20/2009 10:30:00    

How do I do this?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 11 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros