2016-06-14 5 views
-1

私は自分のmysqlクエリで間違いを犯しています。誰も私を助けることができますか?WHERE句でmysqlクエリのelse文を取得する方法は?

select * from user_errors where user_id = '2' 
IF(type = 'custom_type') second_user_id != '2' ELSE second_user_id = '2' 
END IF 
+0

は、エラーメッセージ –

答えて

0

if elseを使用するには、no必要はとにかくこれを試して、ありません。)

select * from user_errors 
where user_id = '2' 
and ((type = 'custom_type' and second_user_id != '2') or second_user_id = '2') 

それとも、これをしようとすると、それを使用する必要があります。)

select * from user_errors 
where user_id = '2' 
and case when type = 'custom_type' then second_user_id != '2' else second_user_id = '2' end 
0

このような用途(あなたドン他の条件の場合に使用する必要があります)

select * from user_errors where user_id = '2' 
and ((type = 'custom_type' and second_user_id != '2') 
or (type != 'custom_type' and second_user_id = '2')) 
0

あなたが使用している `IF()`関数と `IF`` THEN` `ENDのIF`文の違いを指摘している必要があります。この

select * from user_errors 
where user_id = '2' 
IF(type = 'custom_type', second_user_id != '2', second_user_id = '2') 
+0

を投稿してみましたOPはMySQLが両方をサポートしているので、使用しようとしました。 – Marki555

+0

私はあなたのことを理解しませんでした – Qazi

0
SELECT * FROM user_errors 
WHERE user_id = '2'AND (case when type = 'custom_type' then second_user_id != '2' else second_user_id = '2' end)