Select Unique Distinct records for Column

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • philip260@gmail.com

    Select Unique Distinct records for Column

    Im trying to run a query that will pull distinct data not for the
    entire select query but for a single column. Here is my sql statement
    below. Why is it not working? It is probably something stupid. Thanks
    for your help in advance

    SELECT Count(MastrQual ityTbl.[WORK NUMBER]) AS [TOTAL WORK RECEIVED],
    MastrQualityTbl .USERID, MastrQualityTbl .FIRSTNAME,
    MastrQualityTbl .LASTNAME, MastrQualityTbl .TEAM_NAME
    FROM MastrQualityTbl as c1
    WHERE NOT EXISTS (SELECT MastrQualityTbl .[WORK NUMBER] from
    MastrQualityTbl WHERE MastrQualityTbl .[WORK NUMBER] = c1.WORK NUMBER)
    and
    WHERE (((MastrQuality Tbl.DATE) Between
    [Forms]![DashBoardForm]![FromDate] And
    [Forms]![DashBoardForm]![ToDate]) AND ((MastrQualityT bl.CATEGORY) In
    ('NEW BUSINESS')))
    GROUP BY MastrQualityTbl .USERID, MastrQualityTbl .FIRSTNAME,
    MastrQualityTbl .LASTNAME, MastrQualityTbl .TEAM_NAME;

    Im trying to count only the unique WORK NUMBERS in this select
    statement.

  • David Portas

    #2
    Re: Select Unique Distinct records for Column

    philip260@gmail .com wrote:
    Im trying to run a query that will pull distinct data not for the
    entire select query but for a single column. Here is my sql statement
    below. Why is it not working? It is probably something stupid. Thanks
    for your help in advance
    >
    SELECT Count(MastrQual ityTbl.[WORK NUMBER]) AS [TOTAL WORK RECEIVED],
    MastrQualityTbl .USERID, MastrQualityTbl .FIRSTNAME,
    MastrQualityTbl .LASTNAME, MastrQualityTbl .TEAM_NAME
    FROM MastrQualityTbl as c1
    WHERE NOT EXISTS (SELECT MastrQualityTbl .[WORK NUMBER] from
    MastrQualityTbl WHERE MastrQualityTbl .[WORK NUMBER] = c1.WORK NUMBER)
    and
    WHERE (((MastrQuality Tbl.DATE) Between
    [Forms]![DashBoardForm]![FromDate] And
    [Forms]![DashBoardForm]![ToDate]) AND ((MastrQualityT bl.CATEGORY) In
    ('NEW BUSINESS')))
    GROUP BY MastrQualityTbl .USERID, MastrQualityTbl .FIRSTNAME,
    MastrQualityTbl .LASTNAME, MastrQualityTbl .TEAM_NAME;
    >
    Im trying to count only the unique WORK NUMBERS in this select
    statement.

    Replied in microsoft.publi c.sqlserver.pro gramming

    Please do not multi-post.

    --
    David Portas, SQL Server MVP

    Whenever possible please post enough code to reproduce your problem.
    Including CREATE TABLE and INSERT statements usually helps.
    State what version of SQL Server you are using and specify the content
    of any error messages.

    SQL Server Books Online:

    --

    Comment

    Working...