November 13, 2008 at 7:55 am
I have the following code:
Select usage_id,u.Dealer_Id,u.usage_date,u.usage_ipaddress,e.Employee_first_name, Employee_last_name
from usage_data u with (nolock)
Inner JOIN Employee e With (NoLock)
ON u.Dealer_id = e.Dealer_id
WHERE u.Dealer_id IN (660,661,1939,2285)
AND u.Usage_Date > '2008-09-20 00:00:01.001' AND u.Usage_Date < '2008-09-20 23:59:59'
AND usage_type_id = 1
When I run this I get repeative usage_id where there should on be single usage_id per employee.
usage_id Dealer_id Usage_date usage_ipaddres First Last
1321966470002008-09-20 00:19:54.837192.168.1.100xxxxxxxx
1321966470002008-09-20 00:19:54.837192.168.1.100xxxxxxxxx
1321969050002008-09-20 00:52:41.75010.10.10.99xxxxxxxxxx
1321969050002008-09-20 00:52:41.75010.10.10.99xxxxxxxxxxx
1321969050002008-09-20 00:52:41.75010.10.10.99xxxxxxxxxx
1321969050002008-09-20 00:52:41.75010.10.10.99xxxxxxxxxxx
Warm Regards,
Arthur Lorenzini
Sioux Falls, SD
November 13, 2008 at 8:32 am
You have some duplicate data in your join.
you could add distinct to the SELECT list, which would remove duplicates.
November 13, 2008 at 10:38 am
Your join seems wrong. (Without knowing what your data/table structure is, I can't say that it IS wrong, but to me it looks wrong)
Do you have an EmployeeID in both tables you can link on? Or IS dealerID your EmployeeID?
To me it looks like multiple employees might use the same DealerID, and thus you're getting multiple employee names when you run that query.
November 13, 2008 at 10:43 am
You were absolutely correct.
This is the finished statement:
Select u.Dealer_Id, u.usage_date, u.usage_ipaddress, e.Employee_first_name, e.Employee_last_name
from usage_data u with (nolock)
Inner JOIN Employee e With (NoLock)
ON u.employee_id = e.employee_id
WHERE u.Dealer_id IN (660,661,1939,2285)
AND u.Usage_Date > '2008-10-03 00:00:01.001' AND u.Usage_Date < '2008-10-03 23:59:59'
AND usage_type_id = 1
Thanks everybody.
Warm Regards,
Arthur Lorenzini
Sioux Falls, SD
November 13, 2008 at 10:46 am
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply