Query building.

  • I have a table with the fields 'User','Send','Receive' & 'Message'. The user Edita might be in the table 100 times and the user Editb might be in the table 250 times. My goal is to pull one distinct row for each unique user so I can cycle through my results and find out how many unique users are inside the table. Is there a query that can be built to accomplish such a task?

  • two typical methods can be used

    select distinct user from yourtable

    --or

    select user from yourtable group by user

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thank you. I love forums because I always get great responses like this one.

  • Actually if all you want is the count of unique users, don't return them and spin through them that just wastes network bandwidth, etc.. Use a COUNT query instead:

    SELECT

    COUNT(DISTINCT User) AS User_Count

    FROM dbo.YourTable;

    That way you get just the one number you need.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply