MYSQL でユーザー変数を使用すると問題が発生します。これが私が書いたコードです。これはエラーを生成していませんが、望ましい結果を示していません。
set @org_id_list := (select c.id from tbl_companyinformations c
left join tbl_users u on c.user_id = u.id
where u.email_address LIKE '%pdatar%'
);
select * from tbl_c2c_offers where
seller_org_id IN (@org_id_list) or buyer_org_id IN (@org_id_list)
しかし、これを MySQL で実行すると、必要な行が返されません。ユーザー変数の定義に使用した select ステートメントを 2 番目の select ステートメントの where ステートメントにコピーすると、必要な結果が表示されます。つまり、次のコードは必要な結果を生成します。
select * from tbl_c2c_offers where
seller_org_id IN (select c.id from tbl_companyinformations c
left join tbl_users u on c.user_id = u.id
where u.email_address LIKE '%pdatar%'
) or
buyer_org_id IN (select c.id from tbl_companyinformations c
left join tbl_users u on c.user_id = u.id
where u.email_address LIKE '%pdatar%'
);
初めて何を間違っていますか?私が言ったように、ステートメントはエラーを引き起こしませんが、必要な結果は表示されません。
私を助けてくれてありがとう。
乾杯、
プラタメシュ