我想通过多个使用intersect关键字的查询使用订单

时间:2018-07-23 09:14:35

标签: sql oracle plsql

select * from customer intersect 

select * from customer where lower(name) = 'ans' intersect

select * from customer where mobile_num='4777899456'

order by name;

//此查询返回> ORA-00904:“ NAME”:无效的标识符

2 个答案:

答案 0 :(得分:1)

为什么要为此使用intersect?所有表引用都指向同一个表,因此结果集中的所有行都必须具有相同的列。

我认为这可以满足您的要求

select c.*
from customer c
where lower(name) = 'ans' and
      mobile_num = '4777899456'
order by name;

您可能需要select distinct

答案 1 :(得分:0)

将当前查询用作内联视图,并将ORDER BY应用于封闭的SELECT,例如

  SELECT *
    FROM (-- current query starts here
          SELECT * FROM customer
          INTERSECT
          SELECT * FROM customer WHERE LOWER (name) = 'ans'
          INTERSECT
          SELECT * FROM customer WHERE mobile_num = '4777899456'
          -- current query ends here
         )
ORDER BY name;