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 have several chat rooms. Currently, I store the list of chat users in
I have made an AJAX chat using Javascript, PHP, and MySQL. I send the
I have a WCF chat service that accepts duplex tcp connections. A single duplex
I have seen lots of chat examples in Erlang but what about lists, like
I`m writing a chat using WinSock2 and WinAPI functions. And I have a little
Have just started using Google Chrome , and noticed in parts of our site,
I have the following code, intended to log the event when a user closes
Hi all i am developing a chat application ... i have multiple chat windows
I am developing an application in asp.net mvc where i need to have Chat
I have a chat window (using a <div> ) that sometimes needs to get

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.