random query question

  • I have a query that is pulling random records from my table. In my testing, I'm noticing that it's pulling out duplicate names at times. Is there a way to mod my query to not show duplicate names?

    My records can have the same name but different dates assigned to that name. I only want to see the name once.

    Here is my query that I'm currently using for my random:

    DECLARE @selectId TABLE selID int)

    INSERT INTO @selectId

    SELECT TOP 25 selID

    from (select *, row_number() over (partition By saleType order by (select newid())) as RowNo

    from salesFeed) sub

    where location= @location and isSelected is Null and DateClosed is NOT NULL and rowNo <= 8

    UPDATE salesFeed

    SET isSelected = 1

    FROM salesFeed AS F

    INNER JOIN @selectId AS S

    ON F.selID = S.selID

    SELECT * FROM salesFeed AS F

    INNER JOIN @selectId AS S ON F.selID = S.selID

    how can I make it so i'm only seeing my sales guy once regardless of the other fields associated to that sales person?

    example:

    sales_person date open date closed

    Greg 1/1/2008 1/25/2008

    Greg 2/25/2009 2/26/2009

    Kelly 2/5/2005 2/5/2006

    I want to see Greg once in my random if that record is pulled.

    there are times I'm seeing Greg being selected within my random twice due to the date open are different. I don't want that

  • Buddy, can you be more specific with your requirement??

    Please go through this following article and helping us help you?? 🙂

    CLICK HERE FOR FORUM POSTING ETIQUETTES - JEFF MODEN[/url]

    When u do so, i am sure a lot of us will help u instantly...

    So please post

    1. Table Structures - CREATE TABLE scripts

    2. Constraints or Indexes in the table, - CREATE SCRIPTS

    3. SAMPLE DATA - INSERT INTO TABLE scripts

    4. Desired output - some visual representation of this.

  • i'm just looking for pulling random records out (which I showed my query I'm using) and not show the same sales person twice.

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

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