首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在嵌套查询中使用返回超过1条记录的select语句中的where子句

问如何在嵌套查询中使用返回超过1条记录的select语句中的where子句
EN

Stack Overflow用户
提问于 2020-07-23 14:59:36
回答 1查看 114关注 0票数 0

我目前正在尝试进行某种类型的嵌套查询,其中它返回一组满足特定需求的行。

代码语言:javascript
复制
select * from entity 
 where id = (
 select attribute_entity_id from attribute 
 where attribute_type_specification_id = (
 select id from attribute_type_specification  
 where entity_internal_name = 'country'
 )
 ) 
 order by entity_id

虽然这会返回错误:

错误:由用作表达式的子查询返回的多行

这是真的,但我该怎么打这个电话?内部选择可能返回x个id的数目,哪个是有效的?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-23 15:20:32

您是否有理由使用子选择来完成这一任务?

这样做的常规方法是使用联接:

代码语言:javascript
复制
select e.*, ats.entity_internal_name
  from entity e
  join attribute a
    on a.attribute_entity_id = e.id
  join attribute_type_specification ats
    on ats.id = a.attribute_type_specification_id
 where ats.entity_internal_name = 'country'
 order by e.entity_id 
;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63057249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档