Nate_LR
asked on
sql count distinct for total column
I'm trying to create a box total column in a table by counting distinct cases from multiple columns in the same table. I can do this properly when the box total column is in another table, but I can't figure out the self-join or whatever is required when it's in the same table.
UPDATE tblWhCoreBoxTotal
SET BoxTotal =
(SELECT COUNT(*)
FROM
(SELECT DISTINCT f_WellLocationID, AGS_ID, BOX_NUM, WH_LOCATION, f_SAMPLETYPEID
FROM tblWhCoreSample
WHERE tblWhCoreSample.f_WellLocationID = tblWhCoreBoxTotal.f_WellLocID
AND tblWhCoreSample.AGS_ID = tblWhCoreBoxTotal.AGS_ID
) t
)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank-you so much!
UPDATE tblWhCoreBoxTotal
SET BoxTotal =
(SELECT COUNT(distinct f_WellLocationID)
FROM
(SELECT DISTINCT f_WellLocationID, AGS_ID, BOX_NUM, WH_LOCATION, f_SAMPLETYPEID
FROM tblWhCoreSample
WHERE tblWhCoreSample.f_WellLoca
AND tblWhCoreSample.AGS_ID = tblWhCoreBoxTotal.AGS_ID
) t
)