sql - 如何在下一个查询中使用一个查询的结果?
问题描述
我在这里阅读了答案,但我仍然不太确定如何针对表的两列和每个查询的多个结果执行此操作。
因此,第一个查询在我的 Node 应用程序中如下所示:
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
我只需要第二个查询的结果,但我没有实现只执行两个查询的一个查询。有人可以帮我吗?任何帮助表示赞赏。
谢谢!
解决方案
你似乎想要exists
:
select *
from an a
where exists(
select 1
from profiles p
where
p.stype = a.stype and p.lid = s.lid
and p.lid_p = @profile_lid and p.style_p = @profile_stype
)
@profile_lid
并且@profile_stype
是查询的参数 - 我建议在查询字符串中使用而不是连接变量。
推荐阅读
- json - 在 cocapods 包管理器上安装时,Firestore/Firebase 无法正常工作
- swagger - 使用 Swagger UI 和 Swashbuckle 按消费者过滤 API 端点
- javascript - 正确的陈述但不正确的结果
- json - 如何使用 serde 将 JSON 数组反序列化为结构?
- swiftui - SWIFTUI - 使用搜索栏、文本和按钮创建 ForEach
- javascript - react-spring clean scale 和 translateX 转换
- javascript - 如何强制更新我的反应代码中的组件以将深色主题切换为浅色主题
- amazon-web-services - 服务未响应 ping 命令
- android - Kotlin - Android Studio - 公共变量问题
- php - PHP数组从另一个值的函数声明值