我目前正在尝试进行某种类型的嵌套查询,其中它返回一组满足特定需求的行。
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的数目,哪个是有效的?
发布于 2020-07-23 15:20:32
您是否有理由使用子选择来完成这一任务?
这样做的常规方法是使用联接:
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
;https://stackoverflow.com/questions/63057249
复制相似问题