次のようなMySQLクエリがあります。
select
*,
(select meta_value
from nord_usermeta m
where meta_key = 'firm' and user_id = s.user_id
limit 1)
as firm,
(select meta_value f
rom nord_usermeta m
where meta_key = 'first_name' and user_id = s.user_id
limit 1)
as first_name,
(select meta_value
from nord_usermeta m
where meta_key = 'last_name' and user_id = s.user_id
limit 1)
as last_name
from nord_submissions s
order by created_at desc
次に、次のような where 句で絞り込む必要があります。
select
*,
(select meta_value
from nord_usermeta m
where meta_key = 'firm' and user_id = s.user_id
limit 1)
as firm,
(select meta_value
from nord_usermeta m
where meta_key = 'first_name' and user_id = s.user_id
limit 1)
as first_name,
(select meta_value
from nord_usermeta m
where meta_key = 'last_name' and user_id = s.user_id
limit 1)
as last_name
from nord_submissions s
where firm like '%DG%'
order by created_at desc
問題は明らかにサブクエリの使用方法にありますが、where 句でそれを参照する方法が見つかりません。
助けてください。