I have 2 views with data and they are related via an ID column.
我有2个数据视图,它们通过ID列相关。
I need to select from view A some ID's based on another ID. This will often result in a set of ID's.
我需要从视图A中选择一些基于另一个ID的ID。这通常会产生一组ID。
Then I need to use this set of ID's to select rows from another view.
然后我需要使用这组ID从另一个视图中选择行。
I could do this with 2 queries, but I'd like to do it in a single query.
我可以通过2个查询来完成此操作,但我想在一个查询中执行此操作。
How should I do this?
我该怎么做?
2 个解决方案
#1
2
SELECT b.*
FROM ViewA a
INNER JOIN ViewB b
ON a.CommonID = b.CommonID
WHERE a.OtherID = xxx
#2
0
select *
from table1
where id in (
select some_id from table2 where id in (
select some_other_id from table3 where some_condition));
#1
2
SELECT b.*
FROM ViewA a
INNER JOIN ViewB b
ON a.CommonID = b.CommonID
WHERE a.OtherID = xxx
#2
0
select *
from table1
where id in (
select some_id from table2 where id in (
select some_other_id from table3 where some_condition));