Sql 如何在下一个查询中使用一个查询的结果?
我已经阅读了这里的答案,但我仍然不确定如何处理一个表的两列和每个查询的多个结果 因此,在我的节点应用程序中,第一个查询如下所示:Sql 如何在下一个查询中使用一个查询的结果?,sql,node.js,sql-server,subquery,correlated-subquery,Sql,Node.js,Sql Server,Subquery,Correlated Subquery,我已经阅读了这里的答案,但我仍然不确定如何处理一个表的两列和每个查询的多个结果 因此,在我的节点应用程序中,第一个查询如下所示: select stype, lid from Profiles where lid_P=${profile.lid} and stype_P='${profile.stype}'; // result can consist of 1-50 objects 我需要以下查询的结果: select * from an where stype=stype and lid
select stype, lid from Profiles where lid_P=${profile.lid} and stype_P='${profile.stype}';
// result can consist of 1-50 objects
我需要以下查询的结果:
select * from an where stype=stype and lid=lid;
// where lid and stype are results from the other query
我只需要第二个查询的结果,但我无法实现一个同时执行这两个操作的查询。有人能帮我吗?感谢您的帮助
谢谢大家! 您似乎希望存在:
@profile\u lid和@profile\u stype是查询的参数,我建议使用它们,而不是在查询字符串中串联变量。您似乎希望:
@profile\u lid和@profile\u stype是查询的参数,我建议使用它们,而不是在查询字符串中连接变量。您尝试过吗
select *
from an
where (stype, lid) in (select distinct ... <your first query>)
你试过了吗
select *
from an
where (stype, lid) in (select distinct ... <your first query>)
它工作得很好。我会在几分钟内检查您的答案,并根据您的建议更改我的查询!它工作得很好。我会在几分钟内检查您的答案,并根据您的建议更改我的查询!