循环访问具有不同 "id" 值的简单查询



我有一个具有不同id的表,我想将其逐个用于查询。这是我尝试做的伪代码:

select distinct id
from table1
-- for every distinct id above, use that "id" in the query below - 
select xyz... 
where num = id

我想在不使用函数/过程等的情况下使用循环来完成这项工作。

每个循环运行的结果都应该附加到以前的结果中。

如果需要追加所有记录,则无需使用循环。您可以使用如下子查询:

select * from table2
where num in (select id from table1)

最新更新