我有一个内部查询内查询转换后获得更多的记录加入
select * from ASSETVERSION where id in (
select ASSETVERSION_ID from scene_asset where scene_id in(
select scene_id from contentobject_scene where contentobject_id in(
select id from contentobject where course_id = 34660
)
)
)
and LOCATION is not null
当我运行此查询我得到27条记录。现在我转换此查询加入像
select av.* from ASSETVERSION av
inner join scene_asset sa on av.id = sa.assetversion_id
inner join scene s on s.id = sa.scene_id
inner join contentobject_scene co_s on s.id = co_s.scene_id
inner join contentobject co on co.id = co_s.contentobject_id
inner join course c on c.id = co.course_id
where
c.id = 34660
and av.location is not null
当我运行此查询我得到36条记录。当我从av.*
更改为distinct av.*
时,我得到27条记录作为内部查询返回。
当我从distinct av.*
更改为distinct av.id, av.asset_id, av.location, co.name as "Content Object name", s.name as "Scene Name" from ASSETVERSION av
时,我再次获得36条记录。
distinct av.id, av.asset_id, av.location --, co.name as "Content Object name", s.name as "Scene Name" from ASSETVERSION av
工作正常。平均回报27条记录。
有什么办法,我可以适用不同的,以co.name as "Content Object name", s.name as "Scene Name"
像
select distinct av.id, av.asset_id, av.location, distinct co.name as "Content Object name", distinct s.name as "Scene Name"
from ASSETVERSION av ...
,所以我会得到相同的27条记录由内部查询返回?
感谢
当您尝试时发生了什么? – 2013-04-29 11:21:34
@DanBracuk当我尝试选择不同的av.id,av.asset_id,av.location,distinct co.name作为“内容对象名称”,不同的s时,我在关键字'distinct'附近出现语法错误。名称为“场景名称...”。谢谢 来自ASSETVERSION AV ...' – Basit 2013-04-29 11:24:49
区别应该只在您的查询中使用一次 - 选择不同的field1,field2,field3等... – sgeddes 2013-04-29 11:26:06