Home » SQL & PL/SQL » SQL & PL/SQL » unexpected results
unexpected results [message #603] Sun, 24 February 2002 22:35 Go to next message
Sudheer M P
Messages: 3
Registered: February 2002
Junior Member
I am having a doubt regarding Oracle

I have two tables as below

emp
------------
empno number(5)
empname varchar2(10)

desc dept
-----------

deptno number(5)
deptname varchar2(10)

now i gave a query on the tables as follows

select * from emp where empno in(
select empno from dept);

note: don't give the table name as emp in the
sub-query. in the subquery i am giving empno which is not there in table dept. ... that is the catch.

why this query is working even after the subquery is wrong. This query is giving all the records in table emp ... ignoring the subquery.

Please give me an answer

Sudheer M P
Re: unexpected results [message #606 is a reply to message #603] Mon, 25 February 2002 00:06 Go to previous messageGo to next message
pratap kumar tripathy
Messages: 660
Registered: January 2002
Senior Member
subquery does not give error as empno exist in emp table. change it to any other column that does not exist in dept or emp table it will give u error.

your query is similar to the query

select * from emp where empno in(
select emp.empno from dept)
Re: unexpected results [message #633 is a reply to message #603] Mon, 25 February 2002 04:22 Go to previous message
Sudheer M P
Messages: 3
Registered: February 2002
Junior Member
subquery does not give error as empno exist in emp table. change it to any other column that does not exist in dept or emp table it will give u error.
your query is similar to the query

select * from emp where empno in(
select emp.empno from dept)

Thanks for the reply

how is it working. How can u select a column which is not there in that particular table. i did n't understand that. please put some more light into it.

Sudheer M P
Previous Topic: Re:V$Open_Cursors to detect Open Cursors at Runtime
Next Topic: Counter
Goto Forum:
  


Current Time: Fri Apr 26 03:31:15 CDT 2024