当前位置: 动力学知识库 > 问答 > 编程问答 >

oracle - Refer to other SQL SELECT statements aliased as tables in FROM clause

问题描述:

I have a very large query that follows the format below:

select ...

from ( select field1,

field2

from some_table ) table1,

( select field1,

field3

from other_table ) table2

where .....

Is is possible for me to refer to one of the tables "defined" in the from clause, lets say table1, in one of the other table definitions in the from clause?

For example:

select ....

from ( select field1,

field2

from some_table ) table1,

( select table1.field1,

field3

from other_table,

table1 ) table2

where .....

Disclaimer: What I am trying to do is not as simple as the example above. The example is simply to illustrate the idea.

网友答案:
WITH
table1 AS
        (
        SELECT  field1, field2
        FROM    some_table
        ),
table2 AS
        (
        SELECT  field1, field2
        FROM    other_table, table1
        )
SELECT  *
FROM    table2
网友答案:

If you are using SQL 2005, you can use Common Table Expressions for doing what you are trying; Quassnoi gives us an example, in Oracle I don't know how to achieve it though

分享给朋友:
您可能感兴趣的文章:
随机阅读: