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

  • SEARCH
  • Home
  • 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 8412723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:44:48+00:00 2026-06-10T00:44:48+00:00

I have a voting system and I am trying to write a query for

  • 0

I have a voting system and I am trying to write a query for MySQL that will detect which votes are completed so than an email can be sent to the vote’s creator. Votes are complete when (1) their time runs out (already solved that one easily) or (2) when all of the voters have voted.

There are two tables relevant to this. The first table is “votes” where each vote is described and has a unique “vote_id”. The second table is “tickets”. At the vote’s creation, each participant has a ticket created (which has some authentication information). Each ticket has a “vote_id” field which corresponds to that in the “votes” table. So basically, as people vote their corresponding ticket is deleted from the tickets table. This means that the number of rows in “tickets” of a given “vote_id” corresponds to the number of people who didn’t vote.

At first I went to do something like this:

SELECT votes.vote_id
FROM votes, tickets
WHERE votes.vote_id=tickets.vote_id
AND (votes.completion_timestamp < NOW())
HAVING (COUNT(tickets.vote_id) = 0)

But then I realized that…because of the “votes.vote_id=tickets.vote_id” line…I would imagine that means that the votes that have no outstanding tickets would be being ignored. I can think of a lot of inefficient ways to do this, but I would imagine there is a way to do this in MySQL?

Generalized summary of question: Given two tables A and B with a common field F, how do I find all F in A that are not present in B?

  • 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-10T00:44:50+00:00Added an answer on June 10, 2026 at 12:44 am

    To do this efficiently in MySQL requires a trick:

    select v.*
    from votes v
    where votes.completion_timestamp < NOW() and
          not exists (select 1 from tickets t where t.vote_id = v.vote_id)
    

    The SQL that you have is not quite right. The following version should work:

    SELECT distinct votes.vote_id
    FROM votes left outer join
         tickets
         on votes.vote_id=tickets.vote_id
    where votes.completion_timestamp < NOW()) and
          tickets.vote_id is null 
    

    The use of EXISTS vs IN with a subquery is discussed extensively in MySQL documentation (http://dev.mysql.com/doc/refman/5.0/en/subquery-optimization-with-exists.html). The difference versus a left outer join would rest on two things. Join strategy and increase I/O.

    I do not know if the JOIN strategy is difference for the left outer join. I speculate that it shouldn’t be worse than for the EXISTS version. The second point, though, is that the left outer join creates an output set that potentially multiplies the number of rows. The EXISTS version cannot do this.

    After reading documentation, it is possible that the following would be more efficient yet:

    select v.*
    from votes v
    where votes.completion_timestamp < NOW() and
          not exists (select 1 from tickets t where t.vote_id = v.vote_id limit 1)
    

    The limit should short-circuit any evaluation beyond the first row encountered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have a voting system on my website that stores all votes
Are there any requirements gathering tools that have a voting system built in? Using
I am working on a comment voting system. I have a page profile_new.php?id=194 That
I have a voting system which sends an id of the clicked item to
Im trying to implement a voting system similar to stackoverflow and I have something
i have a voting system that you dont have to login to and i
I was having trouble with a voting system that I'm trying to make in
In a voting system I have a line that gives a score as follows:
Which rails voting system plugin or gem that has the following features vote up
I'm trying to build an app for SharePoint in C# that will have a

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.