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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:52:56+00:00 2026-05-30T16:52:56+00:00

I have a reputation system on my site, similar to Stack Overflow, where a

  • 0

I have a reputation system on my site, similar to Stack Overflow, where a member will get points for doing different tasks. One of these tasks is commenting on blog articles.

I only want to give my user 5 points for writing 1 comment on an article. If they write additional comments on the same article, or reply to other comments within that article, they should still only get the first 5 points.

To do this I’ve been querying the blog_comments table first, checking to see if that member has already posted a comment on that article previously, if not, in another query, I will add the 5 points to the members_reputation table. My example below shows this:

SELECT COUNT(*) AS duplicates_found FROM blog_comments
WHERE member_id = 12722 AND article_id = 30202

// in my server-side language I would have
// if duplicates_found = 0 then

INSERT INTO members_reputation (member_id, awarded_for, awarded_when, awarded_what)
VALUES (12722, 'Posted a comment', Now(), 5)

Is there a way to shorten these two queries to make one single one? I was thinking about adding the select query to my insert query as a sub-query, but I’ll be honest, it confused me quite a lot as I’m not even sure I can use INSERT & WHERE together, can I?

Anyway, any suggestions are always gratefully received.

MY ANSWER

Thanks to Michael’s kind answer, the answer to my question is:

INSERT INTO members_reputation (member_id, awarded_for, awarded_when, awarded_what)
SELECT 12722, 'Posted a comment', Now(), 5 FROM DUAL
WHERE NOT EXISTS
(
    SELECT * FROM blog_comments
    WHERE member_id = 12722 AND article_id = 30202
)
  • 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-30T16:52:57+00:00Added an answer on May 30, 2026 at 4:52 pm

    Try this:

    INSERT INTO members_reputation (member_id, awarded_for, awarded_when, awarded_what)
    select 12722, 'Posted a comment', Now(), 5
    where not exists
    (
        select * FROM blog_comments
        WHERE member_id = 12722 AND article_id = 30202
    )
    

    UPDATE:

    @MartinG I don’t have MySQL in my box. I tried it on http://sqlzoo.net though, seems MySQL is like Oracle, SELECT with no source table requires a dummy table, you can use DUAL table in lieu of dummy table

    select 'hello' as "No, it is right!" from dual where 
    exists( SELECT * FROM bbc
      WHERE name = 'China')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on incorporating a reputation system into my site, similar to SO. Here
I'd like to implement a badge/reputation system on one of my site. When a
I'm implementing a Stackoverflow-like reputation system on my rap lyrics explanation site, Rap Genius
I have a couple of models in my system: User Reputation Post Reputation Response
I am trying to implement a system of reputation of users in my site.
Possible Duplicate: Stack Overflow / reddit voting system in php How do voting systems,
In my current web application, I have to create a Reputation Points & Badges
RESOLVED P.S.Because I don't have enough reputation to answer my own question right now
We have a setup where we have multiple instances of an application - one
I have a problem where I have a series of points for a simple,

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.