Note that there are some explanatory texts on larger screens.

plurals
  1. POGiven two tables A and B with a common field F, how do I efficiently find all F in A that are not present in B?
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>At first I went to do something like this:</p> <pre><code>SELECT votes.vote_id FROM votes, tickets WHERE votes.vote_id=tickets.vote_id AND (votes.completion_timestamp &lt; NOW()) HAVING (COUNT(tickets.vote_id) = 0) </code></pre> <p>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?</p> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload