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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:05:10+00:00 2026-05-23T07:05:10+00:00

I have a table in MySQL with multiple of reported events (primary key, date

  • 0

I have a table in MySQL with multiple of reported events (primary key, date submitted, and text). Users can “like”, or “+1” the reports, similar to facebook/google. Right now, a user can “like” a single event infinite times. What’s the best way of arranging the database to check if he’s agreed to this even before?

I considered adding a column that can store a huge amount of text and adding a user to this text block if he agrees (comma seperated). I could then explode the text later and search it to see if his name is in there. However, I figured there must be a better way of going about this – any suggestions?

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

    I’d use three tables: event, user and user_likes_event

    CREATE TABLE `event` (
      `id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
      `submitted` DATE NULL ,
      `text` TEXT NULL ,
      PRIMARY KEY (`id`) )
    ENGINE = InnoDB;
    
    CREATE TABLE `user` (
      `id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
      `name` VARCHAR(45) NULL ,
      PRIMARY KEY (`id`) )
    ENGINE = InnoDB;
    
    CREATE TABLE `user_likes_event` (
      `event_id` INT UNSIGNED NOT NULL ,
      `user_id` INT UNSIGNED NOT NULL ,
      PRIMARY KEY (`event_id`, `user_id`) ,
      INDEX `fk_user_id` (`user_id` ASC) ,
      INDEX `fk_event_id` (`event_id` ASC) ,
      CONSTRAINT `fk_event_id`
        FOREIGN KEY (`event_id` )
        REFERENCES `event` (`id` )
        ON DELETE CASCADE
        ON UPDATE CASCADE,
      CONSTRAINT `fk_user_id`
        FOREIGN KEY (`user_id` )
        REFERENCES `user` (`id` )
        ON DELETE CASCADE
        ON UPDATE CASCADE)
    ENGINE = InnoDB;
    

    Insert some values:

    INSERT INTO `event` (submitted, text) VALUES
    ('2011-06-20', 'Event 1'),
    ('2011-06-21', 'Event 2'),
    ('2011-06-22', 'Event 3');
    
    INSERT INTO `user` (name) VALUES
    ('Tom'), ('Dick'), ('Harry');
    
    INSERT INTO `user_likes_event` (event_id, user_id) VALUES
    (1,1), (1,2), (1,3),
    (2,1), (2,2), (2,3),
    (3,1), (3,2), (3,3);
    

    Every user now likes every event once. If Tom attempts to like Event 1 again, a primary key constraint error is thrown:

    INSERT INTO `user_likes_event` (event_id, user_id) VALUES (1,1);
    
    ERROR 1062 (23000): Duplicate entry '1-1' for key 'PRIMARY'
    

    If you don’t want errors thrown, you could try a conditional insert:

    INSERT INTO `user_likes_event` (event_id, user_id)
    SELECT 1,1 FROM DUAL
    WHERE NOT EXISTS (
        SELECT event_id, user_id   FROM `user_likes_event`
        WHERE event_id = 1 AND user_id = 1
    );
    

    See this question for ideas on INSERT WHERE NOT EXISTS alternatives.

    See the SELECT Syntax for more information on the DUAL table.

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

Sidebar

Related Questions

I have a MySQL table with multiple fields, and I'd like to find any
I have a table in MySQL that has a primary key: mysql> desc gifts;
I have a mysql table with entries like this: id name value date 1
What happens in mysql multiple records insert during an error. I have a table:
I have a table in MYSQL DB with date field in YYYY-mm-dd format. i
Basically, I have multiple URL's stored in a MySQL table. I want to pull
i have table question (mysql with php) which contains question,category(multiple) and subcat(multiple) its belong.
In MySQL table, I have a field called Tag, which may include multiple comma-delimited
I have a table of products, there can be multiple products with the same
I have multiple entries in a mysql table field, these are separated with commas;

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.