I want to get value from table chat using case, like this :
SELECT user_one, user_two
FROM chatting, users
WHERE
CASE
WHEN user_one = 36
THEN user_two = 55
WHEN user_two = 55
THEN user_one = 36
END
Run Code Online (Sandbox Code Playgroud)
but i get this error after "THEN user_two = 55" The error is "Incorrect syntax near '='."
It is not possible to make a logical expression the predicate of a CASE expression. That is, what follows THEN and ELSE has to be literal values. But, we can rewrite your logic as:
SELECT
user_one,
user_two
FROM chatting c
INNER JOIN users u
-- ON <some condition>
WHERE
(user_one = 36 AND user_two = 55) OR (user_one = 55 AND user_two = 36);
Run Code Online (Sandbox Code Playgroud)
Depending on your version of SQL, we might be able to write the WHERE clause using tuples, as:
WHERE
(user_one, user_two) IN ((36, 55), (55, 36));
Run Code Online (Sandbox Code Playgroud)