Archives of the TeradataForum
Message Posted: Fri, 07 Mar 2008 @ 09:32:12 GMT
Subj: | | Re: Teradata Query with Subselect |
|
From: | | Victor Sokovin |
| I have never written SQL with a select nested in the select statement... | |
If you want to try how it works I would suggest Oracle.
SELECT 1, (SELECT 2 FROM dual)
FROM dual;
DUAL is just for illustration purpose, it is a pseudo-table from which you can select whatever you want. We need to use it in Oracle
because Oracle does not like FROM-less queries.
In reality the query would use two different tables. For example, the second SELECT may extract some context specific "constant" from a
reference table which does not have columns which would allow for an obvious JOIN conditions with the main table.
Code generators like this feature very much as it allows them to build complex, yet fast, queries out of different building blocks which would
typically be stored in different tables, without bothering about the columns they can join on. You would often find this type of queries behind
Oracle-based applications where users can freely customize their screens (and, of course, the feeding queries behind them).
Victor
|