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 7735317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:28:18+00:00 2026-06-01T07:28:18+00:00

I have 3 tables with the following columns : * users : user_id *

  • 0

I have 3 tables with the following columns :

* users : user_id
* votes : user_id, creation_id
* creations : creation_id, creation_points

Each user can vote one time for each creation. When a user vote, this happens :

  • Table votes : Insert a new line with user_id and creation_id (so we can check if the user has already voted for this creation)
  • Table creations : Add +1 to row creation_points for the concerned creation

But now, I want that when the user has successfully voted for a creation, it displays him the next creation for which he didn’t vote yet. How can I achieve that ?

I tried this way :

  1. Select the next creation_id from creations table (where creation_id is bigger than the current creation_id)
  2. Check if the couple creation_id & user_id already exists in the votes table. If it exists, retry from 1).

The problem with this method is that it needs a lot of queries if the user has already voted for the next creation. It also create an infinite loop if he has already voted for all the creations. Is there others alternatives ?

  • 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-01T07:28:19+00:00Added an answer on June 1, 2026 at 7:28 am

    If I understand how you are handling it, you seem to be on the right track by storing votes as a user_id and creation_id. To get the next available creation, use a LIMIT 1 query that excludes the already voted-for creations:

    This method uses a NOT IN() subquery:

    SELECT 
     creations.*
    FROM creations 
    WHERE creation_id NOT IN (
      SELECT creation_id FROM votes WHERE user_id = <the user_id>
    )
    ORDER BY creation_id ASC 
    LIMIT 1
    

    Similar thing using NOT EXISTS instead:

    SELECT 
     creations.*
    FROM creations 
    WHERE NOT EXISTS (
      SELECT creation_id 
      FROM votes 
      WHERE 
       user_id = <the user_id>
       AND creations.creation_id = votes.creation_id
    )
    ORDER BY creation_id ASC 
    LIMIT 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one MySQL table, users , with the following columns: user_id (PK) email
I have the following tables (and example values): **user:** user_id (1, 2, 3) username
I have a table [Users] with the following columns: INT SmallDateTime Bit Bit [UserId],
I have 2 mysql tables : Question with the following columns : id, question,
I have 2 mysql tables 1. questions: with the following columns: id, title, answer1,
I have three tables: Project: ... relations: User: local: authorId foreign: id Users: class:
I have two tables, one that stores user earnings and another that stores the
I have the following tables: Table: user_groups (many-to-many) user_id (int) group_id (varchar) Table: profile_groups
I have mysql 2 tables: user_profile_field and user_profile_data with following columns: user_profile_field: -id (integer)
I have the following tables users: uid, name_f, name_l... group_data: id, group_id, admin, invitedusers,

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.