Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8846641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:02:56+00:00 2026-06-14T12:02:56+00:00

Background: I’m currently developing a simple online quiz. After the user has answered a

  • 0

Background: I’m currently developing a simple online quiz. After the user has answered a simple question, the user gets the chance to improve their chances of winning by doing small tasks.

Every lot the user earns is inserted into a separate row, so when I need to find a “random” lot, their chances of winning are increased (please correct me if I’m wrong).

Sample data from the lots table:

LotId      ParticipantId      Created
1          1                  2012-11-16 12:00:00
2          2                  2012-11-16 12:02:00    
3          2                  2012-11-16 12:06:00 
4          2                  2012-11-16 12:15:00    
5          3                  2012-11-16 12:16:00

This means that the participant with ParticipantId 2 has three lots, and therefore a statistically bigger chance of winning compared to the other participants.

What I need to do: When I need to draw a winner, I select a random lot from the lots table. After this I need to find the information on the winner.

Currently I use this following SELECT (any comments on improving the SELECT are appreciated), and then later in my code I have another SELECT with the user’s information.

SELECT TOP 1 LotId, ParticipantId FROM Sample_Lots WITH (NOLOCK)
WHERE
    CAST(Created AS DATE) = '2012-11-16'
    AND
    ParticipantId NOT IN
    (
        SELECT ParticipantId FROM Sample_Winners WITH (NOLOCK)
        WHERE
            ParticipantId IS NOT NULL
            AND
            CAST(ThisDate AS DATE) = '2012-11-16'
    )
    AND
    ParticipantId IN
    (
        SELECT ParticipantId FROM Sample_Participants WITH (NOLOCK)
        WHERE
            ParticipationConfirmed IS NOT NULL
    )
ORDER BY NEWID()

I can’t work my head around this. I need a random lot, and from this random lot I need to get the user’s information in the same SELECT. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:02:57+00:00Added an answer on June 14, 2026 at 12:02 pm

    Assuming your user information is found in a table named Participants, with columns ParticipantId, FirstName, and LastName, here is an example using a JOIN to that table:

    SELECT TOP 1 sl.LotId, sl.ParticipantId, p.FirstName, p.LastName 
    FROM Sample_Lots sl 
    INNER JOIN Participants p ON sl.ParticipantId = p.ParticipantId WITH (NOLOCK)
    WHERE
        CAST(Created AS DATE) = '2012-11-16'
        AND
        sl.ParticipantId NOT IN
        (
            SELECT ParticipantId FROM Sample_Winners WITH (NOLOCK)
            WHERE
                ParticipantId IS NOT NULL
                AND
                CAST(ThisDate AS DATE) = '2012-11-16'
        )
        AND
        sl.ParticipantId IN
        (
            SELECT ParticipantId FROM Sample_Participants WITH (NOLOCK)
            WHERE
                ParticipationConfirmed IS NOT NULL
        )
    ORDER BY NEWID()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I am developing an app which sends an SMS to users after registration
Background Developing a simple web application (Eclipse + JBoss + Apache Tomcat) to generate
Background I graduated 6 months ago, and my collaborative work in college has all
Background I am developing a social web app for poets and writers, allowing them
Background: I have viewed this question as well as this one - sadly, to
Background A lot of work has gone into optimizing database design, especially in the
Background We currently use OpenID for authentication of users, and use the Claimed Identity
Background info: We are currently 3 web programmers (good, real-life friends, no distrust issues).
Background I have written a simple WebGL puzzle game and I want to allow
Background: At my company we are developing a bunch applications that are using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.