JohnDotOwl
JohnDotOwl

Reputation: 3755

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

Upvotes: 0

Views: 55

Answers (1)

lauw
lauw

Reputation: 545

since i dont exactly know what your ideal return result should be you can also have a simple true, false answer with this query:

SELECT if((SELECT count(*) FROM ChatListUsersDB WHERE (UserToken = nr1 OR userToken = nr2)) = 2, 'true', 'false') AS answer

Upvotes: 1

Related Questions