Need help on Query on below requirement.
I have 2 tables.
ID NAME ParentID
1A AAA P1
2A BBB P2
3A CCC P3
P1 DDD Null
P2 EEE NUll
P3 FFF NUll
Parent's ID column and Child's Child column are in primary key -foreign key relation ship.
My requirement is
Need to get Parents names for the children - Name(parent Table) based on the childID (Child Table).
I have written query as below but not getting results
select P.Name from
parent p where P.ID = (
select parentID from parent where
P.ID=(Select c.ChildID from child c where c.classid = 'cls1' ))
Giving error as "Multi part identifier could not be bound" - since with class id "cls1" there
are many childID present in the child table
How do i write this query ??. Do i need to use cursor and get childID one-by-one.
O/p should be as
ChildID ChildNAme ParentName
!A AAA DDD
2A BBB EEE
3A CCC FFF