Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Select records from one table based on the condition from 2nd table in where statement

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-03-15 : 10:05:19
Navinder writes "I am having ASP-SQL 7.0 application.
I am using 2 tables, one is "Employee" having some details of employees with there 'employee_id' as the primary key.
and second one is "Usagetracking" with 2 columns
'login_date'- login dates of an employee on the application
'Employee_id'- Employee id who is logining on to the application.
--------

Now I want employees details from the 'employee' table for only those whose last login_date, means Max(login_date) for a any particular employee, is between the specified set of dates(say between 1/1/2000 to 1/1/2001)

what I am using is:
"Select employee.First_name, employee.Last_name,employee.role from employee,usagetracking where employee.employee_id=UsageTracking.UserID
and DATEDIFF(day, UsageTracking.LoginDate, '1/1/2001') <= 0 and
DATEDIFF(day, UsageTracking.LoginDate, '1/1/2003') >= 0 group by employee.Last_name, employee.First_name,
employee.role order by last_name"

What I am getting is all the records having there any of the 'login_date' between the set of dates but what I want is records having MAX(LOGIN_DATE) in the set of dates.

Please help

regards"

Nazim
A custom title

1408 Posts

Posted - 2002-03-15 : 11:30:47
Select employee.First_name, employee.Last_name,employee.role from employee,usagetracking where employee.employee_id=UsageTracking.UserID
and DATEDIFF(day, UsageTracking.LoginDate, '1/1/2001') <= 0 and
DATEDIFF(day, UsageTracking.LoginDate, '1/1/2003') >= 0 group by employee.Last_name, employee.First_name,
employee.role order by last_name
having logindate=max(logindate)

HTH

--------------------------------------------------------------
Go to Top of Page
   

- Advertisement -