I'm getting a problem using user-variables in MYSQL. Here's the code I've written. This isn't producing any errors but is not showing the desired results.
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)
But then when I run this in MySQL, it doesn't return the required rows. If I copy the select statement used to define the user variable in the where statement of the second select statement, the required results are shown. What I mean is, the following code produces the required results.
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%'
);
What am I doing wrong the first time around? As I said, the statements don't cause any errors, but the required results are not shown.
Thanks in advance for your time in helping me.
Cheers,
Prathamesh