Reputation: 1976
I want to add condition_2 to mysql where clause by test condition_1. condition_1 is type = 'group:1'
and condition_2 is username = 'rahim'
. So, if type = 'group:1'
satisfied, then I going to add username = 'rahim'
in where clause. If not satisfied, I do not want to add this to where clause. I tried username = 'rahim' CASE WHEN type = 'group:1'
. But, it output error:
[Err] 1064 : for the right syntax to use near 'CASE WHEN type = 'group:1' AND type = 'group:1''
SELECT
a.user_id,
b.username,
a.message,
a.type
FROM
livechat_message a
LEFT JOIN livechat_user b ON a.user_id = b.user_id
WHERE
username = 'rahim' CASE
WHEN type = 'group:1'
AND type = 'group:1'
Thanks in advance.
Upvotes: 1
Views: 442
Reputation: 1270191
You would seem to want:
WHERE NOT (type = 'group:1' AND username <> 'rahim')
Upvotes: 1