I get duplicates of a s.Staff_ID. How can i remove duplicates of s.Staff_ID?
Staff_ID is a INT data type and the primary key of the Staff table. I tried "select distinct" but still had duplicate Staff_ID's in the results.
sql = "SELECT l.Staff_Training_ID, s.Staff_ID, s.Staff_LName, s.Staff_MName, s.Staff_FName, s.hphone, s.Hcounty, s.hstreet1, s.hstreet2, s.hcity, s.hstate, s.hzip, s.Emp_DOB, l.Child_Abuse_Dt, l.Food_Handler_Exp_Dt, l.First_Aid_Exp_Dt, l.CPR_Exp_Dt, l.DMV_Record_Dt, l.Drivers_License_Exp_Dt, s.CBR_Comments, CBR_Exp_DT, fsa.Facility_ID, f.Director_Name, f.Site_Phone_No FROM Staff_Training_Log AS l INNER JOIN Staff AS s ON l.Staff_ID = s.Staff_ID AND l.Staff_ID = s.Staff_ID INNER JOIN Facility_Staff_Assoc AS fsa ON l.Staff_ID = fsa.Staff_ID INNER JOIN Facility AS f ON f.Facility_PK = fsa.Facility_ID WHERE facility_ID = " & lv_Facility_ID & " ORDER BY s.Staff_LName;"
that's because the combinations (in the complete table) return distinct values
if one column is distinct of the entire table, sql will show it
take a look
SELECT internal.i FROM (SELECT 1 AS iUNION SELECT 2 AS iunionSELECT 3 AS i) internalSELECT distinct internal.i, internal.o FROM (SELECT 1 AS i, 2 AS oUNION SELECT 1 AS i, 1 AS ounionSELECT 3 AS i, 2 AS o) internal
Distinct will not work because the returned result contain multiple of the same rows i.e. from Staff_Training_Log for a staff, it can be lots of the records
Unless you want to select the latest tranining log or max for that staff only..i.e.
SELECT l.Staff_ID
max(l.Staff_Training_ID) as Staff_Training_ID ,
max(l.Child_Abuse_Dt) as Child_Abuse_Dt,
max(l.Food_Handler_Exp_Dt) as Food_Handler_Exp_Dt,
max(l.First_Aid_Exp_Dt) as First_Aid_Exp_Dt,
max(l.CPR_Exp_Dt) as CPR_Exp_Dt,
max(l.DMV_Record_Dt) as DMV_Record_Dt,
max(l.Drivers_License_Exp_Dt) as Drivers_License_Exp_Dt,
Staff_Training_Log l
Group by l.Staff_ID
) l
INNER JOIN Staff AS s ON l.Staff_ID = s.Staff_ID
INNER JOIN Facility_Staff_Assoc AS fsa ON s.Staff_ID = fsa.Staff_ID
INNER JOIN Facility AS f ON f.Facility_PK = fsa.Facility_ID
WHERE facility_ID = lv_Facility_ID
ORDER BY s.Staff_LName
One staff_ID can have multiple Facility_ID 's. This is my problem. See attached. duplicateStaffId.JPG
awking00
You are selecting far more attributes than your example shows, including a number of what appear to be dates. If you only want one row per staff_id, you need to determine the criteria for that selection, such as a latest date.
if one column is distinct of the entire table, sql will show it
take a look
Open in new window
try this
Open in new window