Retrieve data with Where Clause when data on different Row

I’m facing yet another issue with the following design of database.

Let’s say it’s a list of Chat, and another table, user that belong to that chat.

ChatListDB

  1. ID
  2. last_message

ChatListUsersDB

  1. ID
  2. ChatListDB_ID
  3. UserToken

I would like to check if that Chat exist between these two users “Token1” and “Token2”

I cant simply do a query and put both token in Where Clause because they are on different row obviously.

What I want to achieve

How do i check if lets say ChatListDB’s ID is 1234, How do i check if both token(Token1 & Token2) is already in ChatlistUserDB with the SAME ChatlistDB ID


Source: laravel

Leave a Reply