Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> Re: To write a query without using a sub query
Prasad Kulkarni wrote:
> Hello all,
>
> I am using a free database called 'MySql'. But unfortunately it does
> not support sub queries. Can some one help me to write the query
> without using the sub query.
> For example, my query is something like this:
>
> SELECT emp_name FROM emp
> WHERE emp_num > 0
> and emp_num NOT IN (SELECT supervisor_emp FROM supervisor).
If mysql supports outer joins and temporary tables, you could do this:
{ #Select all recs in emp and join with matching supervisor rec, if any }
SELECT emp_num, emp_name, supervisor_emp FROM emp, OUTER supervisor WHERE emp_num = supervisor_emp INTO TEMP emp_temp_tbl ;
{ #find emps that did not have a match in supervisor } { #Note: emp_temp_tbl cols has the same names as the columns selected
#when TEMP was defined in the select statement above. } SELECT emp_name
FROM emp_temp_tbl WHERE supervisor_emp IS NULL ;
-Helene D. Received on Tue Jul 17 2001 - 21:58:58 CDT