2011-01-31 15 views
0

私はこの質問に対する私のニーズを満たすために必要なSQLを把握できないようです。 は、これまで私が持っている:私が持っている場合SQLでXORのような関数を使用する方法

select * from customformresponses 
INNER JOIN exhibitors ON 
Exhibitors.ExhibitorId= customformresponses.ExhibitorId 
WHERE customformresponses.exhibitorid='8179cde9-b922-430a-9024-bd4cb8b3d05c' 
    and exhibitors.exhibitionID = 'e641a3d4-cb57-4f67-86a1-5c2f4c3cf6e0' 
    and customformresponses.FormID = 'c7f5f0de-35f8-412d-9c91-eaf8bb1a3c26' 

私は3種類のフォームID値の応答を検索する必要があるが、問題のイムが持っている:

customformresponses.FormID = 'c7f5f0de-35f8-412d-9c91-eaf8bb1a3c26' or 
customformresponses.FormID = 'c7f5f0de-35f8-412d-9c91-eaf8bb1a3c26' or 
customformresponses.FormID = 'e69cee39-2519-434d-be3e-516ba156b444' 

そして、それが唯一の最初の結果を返します。真の条件は真の条件ではありません。

この条件を満たす行からすべての結果を返すにはどうすればよいですか?

+0

XORが意味することは、出展者ID /出展者IDがOR条件の1つにのみ一致する必要があるということですか?注:ORの最初の2つの部分は同じです。 – RichardTheKiwi

+0

おそらくかっこが必要です。 'xx AND xx AND xx OR xx OR xx'は'(xx AND xx AND xx)OR xx OR xx'として解析されます。 – pascal

答えて

1

私は、これはあなたがそれが一致exhibitoridとexhibitionidが必要になりますが、フォームIDのために、それは2のいずれかに一致します

select * 
from customformresponses 
INNER JOIN exhibitors 
    ON Exhibitors.ExhibitorId= customformresponses.ExhibitorId 
WHERE customformresponses.exhibitorid='8179cde9-b922-430a-9024-bd4cb8b3d05c' 
AND exhibitors.exhibitionID = 'e641a3d4-cb57-4f67-86a1-5c2f4c3cf6e0' 
AND 
(customformresponses.FormID = 'c7f5f0de-35f8-412d-9c91-eaf8bb1a3c26' 
    OR 
    customformresponses.FormID = 'e69cee39-2519-434d-be3e-516ba156b444') 

後何であるかだと思います。

あなたが二列

exhibitorid  | exhibitionid  | formid 
8179cde9-b922... | c7f5f0de-35f8... | c7f5f0de-35f8-412d-9c91-eaf8bb1a3c26 
8179cde9-b922... | c7f5f0de-35f8... | e69cee39-2519-434d-be3e-516ba156b444 

を持っている場合のみのGUIDとカラム名を繰り返さないためにそうであれば、それらの両方が出力結果セット

0

になります...

SELECT * 
FROM customformresponses 
    INNER JOIN exhibitors ON Exhibitors.ExhibitorId = customformresponses.ExhibitorId 
WHERE (
    CASE customformresponses.exhibitorid WHEN '8179cde9-b922-430a-9024-bd4cb8b3d05c' THEN 1 ELSE 0 END + 
    CASE exhibitors.exhibitionID WHEN 'e641a3d4-cb57-4f67-86a1-5c2f4c3cf6e0' THEN 1 ELSE 0 END + 
    CASE customformresponses.FormID WHEN 'c7f5f0de-35f8-412d-9c91-eaf8bb1a3c26' THEN 1 ELSE 0 END 
) = 1 
0
select * from customformresponses 
INNER JOIN exhibitors  
ON Exhibitors.ExhibitorId= customformresponses.ExhibitorId 
WHERE customformresponses.exhibitorid='8179cde9-b922-430a-9024-bd4cb8b3d05c' 
AND exhibitors.exhibitionID = 'e641a3d4-cb57-4f67-86a1-5c2f4c3cf6e0' 
AND ormresponses.FormID IN ('c7f5f0de-35f8-412d-9c91-eaf8bb1a3c26', 'e69cee39-2519-434d-be3e-516ba156b444') 
関連する問題