Basic T-SQL Join Where…

Lets say you have two tables: Employees and Profile.  You need to find everyone who is over 21.

Employees:
UserID, int
Name, varchar(5)
1, Peter
2, Cathy
3, Manuel
4, Jonathan

Profile:
UserID, int
Birthday, date
1, 2010-03-13
2, 1997-06-21
3, 1988-04-16
4, 2013-08-22

select Name
from Employees as e
join Profile as p on e.UserId=p.UserID
where DATEADD(YY,21,Birthday) < getdate();

Leave A Reply

Your email address will not be published.