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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:46:04+00:00 2026-05-25T06:46:04+00:00

I have table with following structure id int auto increment, primary key uid int

  • 0

I have table with following structure

id         int             auto increment, primary key
uid        int             (comment: userid)
cdt        date/time       (comment: current date)
hits       int             (comment: no. of hits)

Now, I need a query such as

for a particular combination of ‘uid’ and ‘cdt’, if there is row available, then update hits (ie., add 1 to hits) otherwise add new row with ‘uid’ and ‘cdt’ values, and hits set to 1

Let me clear further with example

say uid = 01, and cdt = 2010-01-01, if this combination of uid and cdt is not available in table, then new row should be inserted, otherwise value of hits should be update

How to achieve this?

  • 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-25T06:46:04+00:00Added an answer on May 25, 2026 at 6:46 am

    You could do this in two steps:

    First:
    Query db to know if that particular record is present:

    SELECT id FROM your_table 
    WHERE uid = your_user_id AND cdt = your_date 
    

    Second:
    If previous query returns zero rows:

    INSERT INTO your_table
    (uid, cdt, hits)
    SELECT your_user_id, your_date, 1
    

    else:

    UPDATE your_table
    SET hits = hits + 1
    WHERE uid = your_user_id AND cdt = your_date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two database tables with the following structure: actions: action_id int(11) primary key
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have a table with the following structure, FIELD TYPE EXTRA faciltiy_id int auto_increment(Primary
I have a table with the following structure id(int) | col1(int) | col2(int) |
I have the following table structure CREATE TABLE `table` ( `id` int(11) NOT NULL
Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
I have a table with the following structure: id -int(11) event_id -int(11) photo_id -int(11)
I have a table with the following structure: id int(11), name varchar(250) I have
I have an SQL table with the following structure: Code1 - int Code2 -
I have a table with the following structure: CREATE TABLE `game_entries` ( `id` int(11)

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.