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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:57:09+00:00 2026-05-25T17:57:09+00:00

I have a chat user entry in a MySql table – id (primary key,

  • 0

I have a chat user entry in a MySql table –

id (primary key, autoincrement) – the chat user id
user_id – the users id as it pertains to our product
room_id – the id of the room your in

If a chat operator enters the room, leaves, and then comes back – as it is now – will create two entries in the room (INSERT INTO chatuser …)

I know INSERT IF NOT EXISTS syntax, however I want to IF NOT EXISTS not on the primary key, but WHERE user_id = x AND room_id = y (which will be the same if they re-enter a room they have been in)

something like INSERT INTO chatuser SET user_id=4, room_id=2 IF ENTRY DOESNT EXIST WITH THOSE VALUES ALREADY 😉

thank you

  • 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-25T17:57:10+00:00Added an answer on May 25, 2026 at 5:57 pm

    If you have a unique index on (user_id,room_id), you can do INSERT ... ON DUPLICATE KEY UPDATE (or INSERT IGNORE if you don’t need to update anything when the record already exists):

    INSERT INTO table_1 (user_id, room_id, enter_date)
    VALUES  (1,1, NOW())
    ON DUPLICATE KEY UPDATE
    enter_date = NOW()
    
    // or
    INSERT IGNORE INTO table_1 (user_id, room_id)
    VALUES (1,1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm writing a chat app with php/mysql i have 3 tables: user, room and
I have a database in MYSQL and it has chat table which looks like
I have written a small chat app that uses mysql + php to facilitate
I have hasMany Through table which is Chats table with Chat model and I'm
We have implemented a JQuery chat in our company for internal communications. It is
I have an animation that slides in an image when the user clicks chat
I have several chat rooms. Currently, I store the list of chat users in
I have written a program to integrate Facebook user chat in C#, however I
I want to have a chat box (textarea) where if user press Enter then
I have a javascript chat. When a user receives a message, I want the

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.