数据库嵌套子查询order by 使用

oracle 嵌套子查询使用order by

  例子查询为:

select * from B where name in (    select name from A order by name )

结果报错 "ORA-00907:缺少右括号"

需包装一层 例子为:

select * from B where name in (select * from (select name from A order by name))

 

sqlserver 嵌套子查询使用 order by

例子查询为:

select * from B where name in (    select name from A order by name )

会报错"除非另外还指定了 TOP、OFFSET 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效"

需添加以上指定内容

例 top : 

select * from B where name in (select top(select count(*) from A ) name from A  order by name)

      

你可能感兴趣的:(数据库)