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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:10:04+00:00 2026-05-24T04:10:04+00:00

I want to check if an entry exist, if it does I’ll increment it’s

  • 0

I want to check if an entry exist, if it does I’ll increment it’s count field by 1, if it doesn’t I’ll create a new entry and have it’s count initialize to 1. Simple enough, right? It seems so, however, I’ve stumbled upon a lot of ways to do this and I’m not sure which way is the fastest.

1) I could use this to check for an existing entry, then depending, either update or create:

if(mysql_num_rows(mysql_query("SELECT userid FROM plus_signup WHERE userid = '$userid'")))

2) Or should I use WHERE_EXISTS?

SELECT DISTINCT store_type FROM stores
WHERE EXISTS (SELECT * FROM cities_stores
WHERE cities_stores.store_type = stores.store_type);

3) Or use this to insert an entry, then if it exists, update it:

INSERT INTO table (a,b,c) VALUES (1,2,3)
   ON DUPLICATE KEY UPDATE c=c+1;
UPDATE table SET c=c+1 WHERE a=1;

4) Or perhaps I can set the id column as a unique key then just wait to see if there’s a duplicate error on entry? Then I could update that entry instead.

I’ll have around 1 million entries to search through, the primary key is currently a bigint. All I want to match when searching through the entries is just the bigint id field, no two entries have the same id at the moment and I’d like to keep it that way.

Edit: Oh shoot, I created this in the wrong section. I meant to put it into serverfault.

  • 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-05-24T04:10:05+00:00Added an answer on May 24, 2026 at 4:10 am

    I believe it’s 3.

    Set an INDEX or a UNIQUE constraint and then use the syntax of number 3.

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

Sidebar

Related Questions

In the case when I want to check, if a certain entry in the
I want to check if a Map doesn't contain empty values. If the value
Can I have one query to check if an entry is in a mysql
Using VB.Net and Sql Server I want to check the user Entry Value. The
I want to perform a check is there an entry for each of the
With my application I want to check what list box entry is selected in
I want to check out all files in all subdirectories of a specified folder.
I want to check for the existence of a table with a given ID
I want to check the login status of a user through an ajax request.
I want to check for duplicated words right next to each other, but even

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.