Re: Does a sub-query require an alias ?
Date: 12 Nov 1993 09:27:17 -0700
Message-ID: <2c0dh5$5fa_at_ollie.solbourne.com>
In article <MWICK.93Nov11193242_at_tamora.oberon.com> mwick_at_oberon.com (Mark Wick) writes:
>
>
>> Hello,
>>
>> As the subject says, do I have to have an alias for the table in
>> all the sub-queries that are being used ?
>> Say I have a query
>>
>> select * from table1 a
>> where (a.col1, a.col2) in
>> (select col4, col5
>> from table2)
>>
>>
>> Field names col4 and col5 in the select statement of the subquery
>> do not exist in table2 but exist in table1, the query works
>> without any error message whatsoever. Is this documented somewhere ?
Actually, in the original example, you WOULD NOT need any alias -
SELECT * FROM table1 WHERE (col_1, col2) IN (SELECT col_3, col_4 FROM table2);
this is perfectly valid syntax, as it is NOT a correlated subquery.
This would be a correlated subquery if there were a WHERE CLAUSE in the subquery, that related to the out query. You only NEED to use an alias if you are referring to something in the out query, within the subquery. HOWEVER, you always may use aliases, and they frequently make life simpler.
Good luck
Joy Oberholtzer
(303) 678-4561 Voice (303) 678-4716 Fax
joy_at_Solbourne.com Internet Received on Fri Nov 12 1993 - 17:27:17 CET