Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Why is this query behaving so ?

ngowringowri Member Posts: 1
I'm using Mysql 5.0.15. I'm interested in knowing why the query in red color below is behaving "abnormally". Am i missing something here ? Any pointers are welcome.

create table TblParent ( ParentID int NOT NULL , Name varchar (32) NOT NULL , PRIMARY KEY ( `ParentID` ) ) ;
create table tblChild ( ChildID int NOT NULL , ChildName varchar (32) NOT NULL , PRIMARY KEY ( `ChildID` ) ) ;

insert into tblParent values ('1', 'Parent-1');
insert into tblParent values ('2', 'Parent-2');
insert into tblParent values ('3', 'Parent-3');
insert into tblParent values ('4', 'Parent-4');

insert into tblChild values ('1', 'Child-1');
insert into tblChild values ('2', 'Child-2');
insert into tblChild values ('3', 'Child-3');
insert into tblChild values ('4', 'Child-4');

-- Next select query below shows four rows as expected

select * from tblParent
where parentid in (
select parentid from tblChild ) ;

[color=Red]-- For the following select query, i expect it to return three rows, at least. But, it returns 0 rows.

select * from tblParent
where parentid in (
select distinct childid from tblChild
where childid < tblParent.parentid
) ;
[/color]

Sign In or Register to comment.